Skip to content

Instantly share code, notes, and snippets.

@KinoAR
Created January 24, 2019 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KinoAR/de04d7d0224b214cd14d4a2cde0b41cd to your computer and use it in GitHub Desktop.
Save KinoAR/de04d7d0224b214cd14d4a2cde0b41cd to your computer and use it in GitHub Desktop.
An example of a monad written in ReasonML.
type collection('a) = Collection('a) | None;
module CollectionMonad = {
let lift = (value) => Collection(value);
let map = (fn, x) => {
switch (x) {
| Collection(value) => Collection(fn(value))
| None => None
}
}
let flatMap = (fn, collection) => switch(collection) {
| Collection(value) => fn(value)
| None => None
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment