Function vector slicing

I have a feature vector (def my-func [a b c d]). Each function takes the output of the last function as input. I want to stream through them through them, how to do it?

How to proceed to the next form (-> in a b c d)?

Thank you Murtaza

+5
source share
2 answers

You can use comp, but keep in mind that it performs functions from 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.

+5
source

I think you can use the function reduce:

(def fns [inc inc inc])
(reduce (fn [v f] (f v)) 10 fns)
+5
source

All Articles