Skip to content

Instantly share code, notes, and snippets.

@Bronsa
Created February 14, 2012 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bronsa/1828382 to your computer and use it in GitHub Desktop.
Save Bronsa/1828382 to your computer and use it in GitHub Desktop.
(defn fnil [f & vals]
(fn [& args]
(apply f (loop [acc [] maybe-nils args vals vals]
(if maybe-nils
(if (nil? (first maybe-nils))
(recur (conj acc (first vals)) (next maybe-nils) (rest vals))
(recur (conj acc (first maybe-nils)) (next maybe-nils) vals))
acc)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment