Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Is there any idiomatic way to do some thing similar to what the -> macro does, but with a dynamic list of functions?
I.e. apply every function in a vector to the output of the last function (all functions take one argument)
A typical idiom is
(reduce #(%2 %) init fns)
For example,
(reduce #(%2 %) 0 [inc #(* 40 %) inc inc]) ;=> 42
Add a comment
You can use the build-in comp function. You will want something like:
(defn f [fns & args] (let [all-fns (apply comp (reverse fns))] (apply all-fns args)))
And use it like:
(f [+ -] 1 2 3) ; -6
fns
rseq
reverse
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.