Skip to content

Instantly share code, notes, and snippets.

@swannodette
Last active December 20, 2015 18:38
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 swannodette/6176916 to your computer and use it in GitHub Desktop.
Save swannodette/6176916 to your computer and use it in GitHub Desktop.
(defn fn->ilookup [f]
(reify
ILookup
(-lookup [coll k]
(-lookup coll k nil))
(-lookup [coll k not-found]
(f k))))
(get (fn->ilookup inc) 0) ;; 1
(let [{x 0 y 1} (fn->ilookup inc)]
[x y]) ;; [1 2]
(defn app [f]
(fn [args]
(apply f args)))
(let [{f [inc dec]} (fn->ilookup (app juxt))]
(f 0)) ;; [1 -1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment