Created
May 17, 2018 14:23
-
-
Save JamieDixon/a890c744814911c85c5af5cbfa40b4bf to your computer and use it in GitHub Desktop.
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
const g = z => z + 1; | |
g(0) // 1 | |
const maybeValue = Maybe.of(0); | |
maybeValue.map(g) // Maybe(1) | |
Function.prototype.map = function (fn) { | |
return compose(fn, this); | |
} | |
Function.prototype.contramap = function(fn) { | |
return leftCompose(fn, this); | |
} | |
const greet = name => `Hello ${name}`; | |
greet('Jamie') // Hello Jamie. | |
const upperGreeter = greet.map(toUpper); | |
upperGreeter('Jamie') // HELLO JAMIE. | |
const newUpperGreter = greet.contramap(toUpper); | |
newUpperGreter('Jamie') // Hello JAMIE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment