Created
May 12, 2020 07:54
-
-
Save zaetrik/425345970034ecc1053fdce169a14c41 to your computer and use it in GitHub Desktop.
Monads: Example
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
import * as O from "fp-ts/lib/Option"; | |
const addTwo = (x: number) => some(x + 2); | |
// Now we can work with nested contexts, thanks to chain/flatMap in our Monad instance | |
O.chain(addTwo)(O.some(5)); // => Option<number> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment