Skip to content

Instantly share code, notes, and snippets.

@vvgomes
Created February 8, 2016 05:52
Show Gist options
  • Save vvgomes/2d8783bd61bc510697e4 to your computer and use it in GitHub Desktop.
Save vvgomes/2d8783bd61bc510697e4 to your computer and use it in GitHub Desktop.

Flip Function in Clojure

Recently, 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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment