Make --map-when accept a predicate function instead of a form
This makes it look a little cleaner: (list (--map-when odd? (* it 3) [1 2 3 4 5]))
This commit is contained in:
parent
8e44cc3d9a
commit
20df6a5532
@ -137,13 +137,12 @@
|
||||
(yield (f v)))))
|
||||
|
||||
|
||||
(defmacro --map-when [pred rep lst]
|
||||
`(let [[p (lambda [it] ~pred)]
|
||||
[f (lambda [it] ~rep)]]
|
||||
(foreach [v ~lst]
|
||||
(if (p v)
|
||||
(yield (r v))
|
||||
(yield v)))))
|
||||
(defmacro --map-when [predfn rep lst]
|
||||
`(let [[f (lambda [it] ~rep)]]
|
||||
(foreach [it ~lst]
|
||||
(if (~pred it)
|
||||
(yield (f it))
|
||||
(yield it)))))
|
||||
|
||||
|
||||
(defmacro --filter [form lst]
|
||||
|
@ -413,10 +413,9 @@
|
||||
(assert-equal (list (--map (* it 3) []))
|
||||
[]))
|
||||
|
||||
|
||||
(defn test-anaphoric-map-when []
|
||||
"NATIVE: testing anaphoric map-when"
|
||||
(assert-equal (list (--map-when (even? it) (* it 2) [1 2 3 4]))
|
||||
(assert-equal (list (--map-when even? (* it 2) [1 2 3 4]))
|
||||
[1 4 3 8]))
|
||||
|
||||
(defn test-anaphoric-filter []
|
||||
|
Loading…
Reference in New Issue
Block a user