Last active
March 25, 2018 16:10
-
-
Save shovon/5685073d03829f3b63d0 to your computer and use it in GitHub Desktop.
Haskell-style monads in JavaScript (ES6).
This file contains 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
'use strict'; | |
class Monad { | |
constructor(a) { this._value = a; } | |
'>>='(f) { return f(this.value()); } | |
static create(a) { return new Monad(a); } | |
value() { return this._value; } | |
} | |
var val = Monad.create(10) ['>>='] | |
(x => Monad.create(x*x) ['>>='] | |
(x => Monad.create(x - 42) ['>>='] | |
(x => Monad.create(x + 3)) )) | |
.value(); | |
console.log(val); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment