I have the following function
(defn fun [a b] (str a b))
(fun "1" "2") ;; --> "12"
Thanks to (partial)
I can turn it into (fun b)
and have a fixed a
(def fun2 (partial fun "1"))
(fun2 "2") ;; --> "12"
Does clojure have something like (partial-right)
or a way to rearrange the arguments of a function so that instead of having a fixed a
I can have a fixed b
and hence have the function (fun a)
?
Thanks
(defn partial-right [f & args1]
(fn [& args2]
(apply f (concat args2 args1))))
But ask yourself...why isn't this already part of the standard library? Is it perhaps that other people have wandered this way and it turned out badly?
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