Created
June 18, 2018 09:45
-
-
Save zackferrofields/96a490625585698622a53189dd3041fe to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let return = (a: 'a) : option('a) => Some(a); | |
let bind = (m: option('a), f: 'a => option('b)) : option('b) => | |
switch (m) { | |
| None => None | |
| Some(a) => f(a) | |
}; | |
let (>>=) = bind; | |
/* module Example = { | |
open MaybeMonad; | |
type xyz = { | |
x: string, | |
y: string, | |
z: string, | |
}; | |
type maybeXYZ = | |
option( | |
{ | |
. | |
"x": option(string), | |
"y": option(string), | |
"z": option(string), | |
}, | |
); | |
let getXYZ = (maybe: maybeXYZ) : option(xyz) => | |
maybe | |
>>= ( | |
condition => | |
condition##x | |
>>= ( | |
xValue => | |
condition##y | |
>>= ( | |
yValue => | |
condition##z | |
>>= (zValue => Some({x: xValue, y: yValue, z: zValue})) | |
) | |
) | |
); | |
}; */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment