Skip to content

Commit 29fafb7

Browse files
authored
Add build-list-const-to-make-list rule (#417)
1 parent 696e9ba commit 29fafb7

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

default-recommendations/list-shortcuts-test.rkt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,16 @@ test: "used map expression not refactorable to for-each"
179179
(define (f func xs ys zs)
180180
(map func xs ys zs))
181181
------------------------------
182+
183+
184+
test: "build-list with const refactorable to make-list"
185+
------------------------------
186+
(require racket/function
187+
racket/list)
188+
(build-list 5 (const 42))
189+
------------------------------
190+
------------------------------
191+
(require racket/function
192+
racket/list)
193+
(make-list 5 42)
194+
------------------------------

default-recommendations/list-shortcuts.rkt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
(require (for-syntax racket/base)
13+
racket/function
1314
racket/list
1415
racket/set
1516
rebellion/private/static-name
@@ -132,9 +133,17 @@
132133
(body-before ... (~replacement (for-each proc list ...) #:original map-expr) body-after ...))
133134

134135

136+
(define-refactoring-rule build-list-const-to-make-list
137+
#:description "Using `build-list` with `const` is equivalent to using `make-list`."
138+
#:literals (build-list const)
139+
(build-list count (const elem))
140+
(make-list count elem))
141+
142+
135143
(define-refactoring-suite list-shortcuts
136144
#:rules (append-single-list-to-single-list
137145
append*-and-map-to-append-map
146+
build-list-const-to-make-list
138147
equal-null-list-to-null-predicate
139148
filter-to-remove*
140149
filter-to-remq*

0 commit comments

Comments
 (0)