Skip to content

Commit

Permalink
Add build-list-const-to-make-list rule (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfirth authored Nov 22, 2024
1 parent 696e9ba commit 29fafb7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions default-recommendations/list-shortcuts-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,16 @@ test: "used map expression not refactorable to for-each"
(define (f func xs ys zs)
(map func xs ys zs))
------------------------------


test: "build-list with const refactorable to make-list"
------------------------------
(require racket/function
racket/list)
(build-list 5 (const 42))
------------------------------
------------------------------
(require racket/function
racket/list)
(make-list 5 42)
------------------------------
9 changes: 9 additions & 0 deletions default-recommendations/list-shortcuts.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


(require (for-syntax racket/base)
racket/function
racket/list
racket/set
rebellion/private/static-name
Expand Down Expand Up @@ -132,9 +133,17 @@
(body-before ... (~replacement (for-each proc list ...) #:original map-expr) body-after ...))


(define-refactoring-rule build-list-const-to-make-list
#:description "Using `build-list` with `const` is equivalent to using `make-list`."
#:literals (build-list const)
(build-list count (const elem))
(make-list count elem))


(define-refactoring-suite list-shortcuts
#:rules (append-single-list-to-single-list
append*-and-map-to-append-map
build-list-const-to-make-list
equal-null-list-to-null-predicate
filter-to-remove*
filter-to-remq*
Expand Down

0 comments on commit 29fafb7

Please sign in to comment.