Skip to content

Instantly share code, notes, and snippets.

@zackferrofields
Created June 18, 2018 09:45
Show Gist options
  • Save zackferrofields/96a490625585698622a53189dd3041fe to your computer and use it in GitHub Desktop.
Save zackferrofields/96a490625585698622a53189dd3041fe to your computer and use it in GitHub Desktop.
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