Skip to content

Instantly share code, notes, and snippets.

@itang
Created October 21, 2015 03:39
Show Gist options
  • Save itang/aaaac23a2ae898c95a90 to your computer and use it in GitHub Desktop.
Save itang/aaaac23a2ae898c95a90 to your computer and use it in GitHub Desktop.
Option for Elm lang
module Option where
type Option a = None | Some a
getOrElse : Option a -> a -> a
getOrElse o e =
case o of
None -> e
Some a -> a
map : (a -> result) -> Option a -> Option result
map f o =
case o of
Some a -> Some (f a)
None -> None
flatMap : (a -> Option b) -> Option a -> Option b
flatMap f o =
case o of
Some a -> f a
None -> None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment