Created
December 18, 2019 15:13
-
-
Save ythirion/529cd3c2e659f7136f4e622fa4b2c630 to your computer and use it in GitHub Desktop.
Option monad
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
Option<int> aValue = 2; | |
aValue.Map(x => x + 3); // Some(5) | |
Option<int> none = None; | |
none.Map(x => x + 3); // None | |
//Left -> Some, Right -> None | |
aValue.Match(x => x + 3, () => 0); // 5 | |
none.Match(x => x + 3, () => 0); // 0 | |
// Returns the Some case 'as is' -> 2 and 1 in the None case | |
int value = aValue.IfNone(1); | |
int noneValue = none.IfNone(42); // 42 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment