curry

curry :: Function f => Function g

description

Returns a curried version of the provided function. Currying is a very important concept in functional programming: it enables partial application, which in turn allows you to reuse these partially-applied functions and to avoid code repetition. curry is a pure function and will return a new function, without modifying the original function. The new function will have the same arity as the original one did.

curry does a little more than classic currying: the returned function can actually accept more than one argument. It can accept from one up to as many as the original function did.

examples

basic example

import { curry } from 'conductor'

const multiply = (x, y) => x * y
const times2 = curry(multiply)(2)

times2(5) // 10

arity preservation

import { curry } from 'conductor'

const multiply = (x, y) => x * y
multiply.length // 2
curry(multiply).length // 2

The resulting function has the same arity as the original.

deep currying

passing more than one argument

Last updated