Skip to content

Instantly share code, notes, and snippets.

@ympbyc
Last active November 28, 2016 01:58
Show Gist options
  • Save ympbyc/e529dfceb3e3286dd381 to your computer and use it in GitHub Desktop.
Save ympbyc/e529dfceb3e3286dd381 to your computer and use it in GitHub Desktop.
Option map digging w/ method-missing
(= (some a (Option a)) x x)
(= (some? (Option a) Bool) x (not (none? x)))
(= (none (Option a)) nil)
(= (none? (Option a) Bool) x (nil? x))
(= (get (Option a) a) x x)
(= (get-or-else (Option a) a a)
opt default
(some? opt (get opt) default))
(= (fmap (Option a) (Fn a (Option a)) (Option a))
opt f
(none? opt none
(f (get opt))))
(= (method-missing (Option (Map Kw a)) Kw (Option a))
opt method-name
(fmap opt (^ dict (get dict method-name))))
(= (get (Map a b) a (Option b))
dict key
(find key dict))
(= (project (HMap :creator (Option (HMap :address ...))
:name (Option Str)))
{:name "Sample Project"
:creator {:name "Jimmy"
:address {:country {:name "Japan"
:capital {:name "Tokyo"
:weather "sunny"}}}}})
(weather (capital (country (address (creator project)))))
(= (-> a (Fn b c) (Fn a b) c)
x f g (f (g x)))
(= (<- a a) x x)
(-> project
-> creator
-> address
-> country
-> capital
<- weather)
;;the clj extension is just for syntax highlighting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment