Skip to content

Instantly share code, notes, and snippets.

@KinoAR
Created January 24, 2019 11:05
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/addad280817e11fc7d4fc93d531f1f9c to your computer and use it in GitHub Desktop.
Save KinoAR/addad280817e11fc7d4fc93d531f1f9c to your computer and use it in GitHub Desktop.
An example of a monad in Javascript
const arr = [1, 2, 3]; //The values 1, 2, 3 have been "returned"/"lifted" into the container(array)
const newArr = arr.map(x => x * 2);//The values are used to create new values; referred to as map
const value = arr[1]; // 2 -The value is taken out of the container; referred to as flatMap,bind, etc.
const value2 = newArr[1];//4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment