Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure partial right

Tags:

clojure

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

like image 973
pistacchio Avatar asked Dec 15 '15 09:12

pistacchio


1 Answers

(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?

like image 170
Antony Woods Avatar answered Oct 02 '22 01:10

Antony Woods