Last active
November 1, 2018 22:56
-
-
Save anabastos/5de131c8d62c86d410fdf4113adb4c4e to your computer and use it in GitHub Desktop.
Pipe Functor
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
const Container = function(val) { | |
this.value = val; | |
} | |
Container.of = function(value) { | |
return new Container(value); | |
} | |
Container.prototype.map = function(fn) { | |
Container.of(fn(this.value)); | |
} | |
const double = x => x * 2; | |
const minus1 = x => x - 1; | |
console.log(Container.of([0, 1, 2, 3, 4, 5]) | |
.map(double) | |
.map(minus1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment