Skip to content

Instantly share code, notes, and snippets.

@rajaraodv
Last active February 8, 2019 13:45
Show Gist options
  • Save rajaraodv/cae512fc3fc19cff082549ee19f62b5d to your computer and use it in GitHub Desktop.
Save rajaraodv/cae512fc3fc19cff082549ee19f62b5d to your computer and use it in GitHub Desktop.
A sample custom functor
const add1 = (a) => a + 1;
class MyFunctor { //Custom "Functor"
constructor(value) {
this.val = value;
}
map(fn) { //Applies function to this.val + returns new Myfunctor
return new Myfunctor(fn(this.val));
}
}
//temp is a Functor instance that's storing value 1
let temp = new MyFunctor(1);
temp.map(add1) //-> temp allows us to map "add1"
@satishgowda28
Copy link

return new Myfunctor(fn(this.val));

Myfunctor
to
MyFunctor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment