Last active
February 24, 2020 02:31
-
-
Save sym3tri/4370733 to your computer and use it in GitHub Desktop.
Simple Monad example in JavaScript
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
// as discussed by Crockford here: http://www.youtube.com/watch?v=dkZFtimgAcM | |
// more detailed example here: https://github.com/douglascrockford/monad/blob/master/monad.js | |
function MONAD() { | |
return function unit(value) { | |
var monad = Object.create(null); | |
monad.bind = function (func) { | |
return func(value); | |
}; | |
return monad; | |
}; | |
} | |
var identity = MONAD(); | |
var monad = identity('hello world'); | |
monad.bind(alert); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment