Created
May 12, 2020 07:23
-
-
Save zaetrik/4ec1251ea1014a65792fdf6e6fd3f23a to your computer and use it in GitHub Desktop.
Monads: Flatten
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
// Taken from https://dev.to/gcanti/getting-started-with-fp-ts-monad-6k | |
import { isNone } from 'fp-ts/lib/Option' | |
// flatten takes in a nested context like Option<Option<A>> and flattens/unwraps it to Option<A> | |
// We do this by returning the value from the nested context Option<Option<A>> which is Option<A> | |
const flatten = <A>(mma: Option<Option<A>>): Option<A> => (isNone(mma) ? none : mma.value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment