The Robin
λxyz.yzx
Clojure
(fn [x] (fn [y] (fn [z] ((y z) x)))
Because Clojure prefers variadic functions to curried functions, we need to make our own curried-map function
(defn cmap [x] (partial map x))
So if our Ruby map function call example looks like this:
(main) > [1, 2, 3, 4, 5].map do |num|
* sqr = num * num
* puts "The square of #{num} is #{sqr}"
* sqr
* end
The square of 1 is 1
The square of 2 is 4
The square of 3 is 9
The square of 4 is 16
The square of 5 is 25
=> [1, 4, 9, 16, 25]
Using cmap and the Robin, our Clojure function looks just like the Ruby function call:
#'user=> ((((fn [x] (fn [y] (fn [z] ((y z) x))))
#_=>
#_=> [1 2 3 4 5]) cmap) (fn [num]
#_=> (let [sqr (* num num)]
#_=> (println "The square of " num "is " sqr)
#_=> sqr
#_=> )))
The square of 1 is 1
The square of 2 is 4
The square of 3 is 9
The square of 4 is 16
The square of 5 is 25
(1 4 9 16 25)