Skip to content

Instantly share code, notes, and snippets.

@JamieDixon
Created May 17, 2018 14:23
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 JamieDixon/a890c744814911c85c5af5cbfa40b4bf to your computer and use it in GitHub Desktop.
Save JamieDixon/a890c744814911c85c5af5cbfa40b4bf to your computer and use it in GitHub Desktop.
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