Skip to content

Instantly share code, notes, and snippets.

@sgrove
Last active June 26, 2019 07:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgrove/600eeb97a70b4cd6c9b54041281ee503 to your computer and use it in GitHub Desktop.
Save sgrove/600eeb97a70b4cd6c9b54041281ee503 to your computer and use it in GitHub Desktop.
let default = (value, opt) =>
switch (opt) {
| None => value
| Some(value) => value
};
let expect = (name, opt) =>
switch (opt) {
| None => raise(Failure("Missing value for " ++ name))
| Some(value) => value
};
let map = (opt, update) =>
switch (opt) {
| None => None
| Some(value) => Some(update(value))
};
let fmap = (opt, update) =>
switch (opt) {
| None => None
| Some(value) => update(value)
};
let fmapDefault = (default, opt, update) =>
switch (opt) {
| None => default
| Some(value) => update(value)
};
let effectMap = (opt, f) =>
switch (opt) {
| None => ()
| Some(value) => f(value)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment