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)))))
|
(yield (f v)))))
|
||||||
|
|
||||||
|
|
||||||
(defmacro --map-when [pred rep lst]
|
(defmacro --map-when [predfn rep lst]
|
||||||
`(let [[p (lambda [it] ~pred)]
|
`(let [[f (lambda [it] ~rep)]]
|
||||||
[f (lambda [it] ~rep)]]
|
(foreach [it ~lst]
|
||||||
(foreach [v ~lst]
|
(if (~pred it)
|
||||||
(if (p v)
|
(yield (f it))
|
||||||
(yield (r v))
|
(yield it)))))
|
||||||
(yield v)))))
|
|
||||||
|
|
||||||
|
|
||||||
(defmacro --filter [form lst]
|
(defmacro --filter [form lst]
|
||||||
|
@ -413,10 +413,9 @@
|
|||||||
(assert-equal (list (--map (* it 3) []))
|
(assert-equal (list (--map (* it 3) []))
|
||||||
[]))
|
[]))
|
||||||
|
|
||||||
|
|
||||||
(defn test-anaphoric-map-when []
|
(defn test-anaphoric-map-when []
|
||||||
"NATIVE: testing 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]))
|
[1 4 3 8]))
|
||||||
|
|
||||||
(defn test-anaphoric-filter []
|
(defn test-anaphoric-filter []
|
||||||
|
Loading…
Reference in New Issue
Block a user