Last active
August 29, 2015 14:26
-
-
Save smockle/236ec200c56e257e33b2 to your computer and use it in GitHub Desktop.
2 ways to write a Functor? (https://github.com/DrBoolean/mostly-adequate-guide/blob/master/ch8.md)
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
class Container { | |
constructor(x) { | |
this.__value = x; | |
} | |
static of(x) { | |
return new Container(x); | |
} | |
map(f) { | |
return Container.of(f(this.__value)); | |
} | |
}; | |
export default Container; |
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
var Container = function (x) { | |
this.__value = x; | |
}; | |
Container.of = function(x) { | |
return new Container(x); | |
}; | |
Container.prototype.map = function(f) { | |
return Container.of(f(this.__value)); | |
}; | |
export default Container; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment