Skip to content

Instantly share code, notes, and snippets.

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 HenriqueLimas/2d63dc9f569f54a3b3605e13b1f1697e to your computer and use it in GitHub Desktop.
Save HenriqueLimas/2d63dc9f569f54a3b3605e13b1f1697e to your computer and use it in GitHub Desktop.

Currying

Ramda and lodash/fp already curry a lot of functions.

Currying: if you know the function is curried, ex the docs say that a function has 3 arguments, if you execute the first time with one argument, it will return a new function.

Compose

Functions can "meld" aka compose. If we have functions f, g and h.

  • Zooming way out from code
  • You start seeing similarities
  • Pure functions are the arrows of a "category"
function compose(g, f) {
	return function (x) {
		return g(f(x))
	}
}

Example from the exercise, better than use composition

var isAuthor = function (name, articles) {
    return _.contains(name, names(articles));
};

Origami programming article

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