Added ap-pipe and ap-compose macros

`ap-pipe` is an anaphoric version of `->` and `->>`. It is useful for
specifying where the argument should go in each expression.

`ap-compose` returns a function which is the composition of several
anaphoric forms.
This commit is contained in:
nicolas-p 2015-04-03 23:02:39 +02:00
parent 3d41630219
commit d3d24db8bd

View File

@ -109,3 +109,15 @@
`(let [[acc ~initial-value]]
(ap-each ~lst (setv acc ~form))
acc)))
(defmacro ap-pipe [var &rest forms]
"Pushes a value through several forms.
(Anaphoric version of -> and ->>)"
(if (empty? forms) var
`(ap-pipe (let [[it ~var]] ~(first forms)) ~@(rest forms))))
(defmacro ap-compose [&rest forms]
"Returns a function which is the composition of several forms."
`(fn [var] (ap-pipe var ~@forms)))