Last active
February 8, 2019 13:45
-
-
Save rajaraodv/cae512fc3fc19cff082549ee19f62b5d to your computer and use it in GitHub Desktop.
A sample custom 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 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
return new Myfunctor(fn(this.val));