Created
October 21, 2015 03:39
-
-
Save itang/aaaac23a2ae898c95a90 to your computer and use it in GitHub Desktop.
Option for Elm lang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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