I have a vector of functions (def my-func [a b c d])
. Each function takes the output of the last function as the input. I want to thread an input through them, how do I do that?
How do I get to the following form (-> in a b c d)
?
Thanks, Murtaza
You can use comp
but be aware it executes the functions right to left
((comp d c b a) 10)
or
((apply comp my-fns) 10)
will pass 10 to the first function, the result to the next function and so on.
I think you can use the reduce
function:
(def fns [inc inc inc])
(reduce (fn [v f] (f v)) 10 fns)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With