Skip to content

Instantly share code, notes, and snippets.

@anabastos
Last active November 1, 2018 22:56
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 anabastos/5de131c8d62c86d410fdf4113adb4c4e to your computer and use it in GitHub Desktop.
Save anabastos/5de131c8d62c86d410fdf4113adb4c4e to your computer and use it in GitHub Desktop.
Pipe Functor
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