function MONAD() {
let prototype = Object.create(null)
function unit(value) {
let monad = Object.create(prototype)
monad.bind = function (func, args) {
return func(value, ...args)
}
return monad
}
unit.lift = function (name, func) {
prototype[name] = function (...args) {
return unit(this.bind(func, args))
}
return unit
}
return unit
}
let ajax = MONAD().lift('log', console.log)
let monad = ajax("Hello world")
monad.log()
To embed this project on your website, copy the following code and paste it into your website's HTML: