Clojure Flip
- 1 minRecently, I found myself in need of a flip function in Clojure. Since I could not find anything in the official documentation, Stackoverflow, or Freenode, I came up with this:
(defn flip [f]
(comp (partial apply f) reverse list))
Its behavior can be described like this (assuming Midje):
(facts "about flip"
((flip -) 1 2) => 1
((flip /) 1 2) => 2
((flip >) 1 2) => true
((flip str) 'foo 'bar 'baz) => "bazbarfoo")
Please, let me know in case you have a simpler solution ;)