curryN

curryN :: (Number arity, Function f) => Function g

description

Returns a curried version of the provided function. The new function will have the specified arity. curry is a pure function and will return a new function, without modifying the original function.

curryN is very similar to curry, except you need to explictly provide the desired arity. curry actually uses curryN internally and is defined as follows: curry = fn => curryN(fn.length, fn). In most cases, curry or arity will be better suited to your needs. The only case where you might want to use curryN would be if your function's length property does not reflect its actual arity (either because it uses the spread parameter operator, or uses the arguments local variable internally).

examples

basic example

import { curryN } from 'conductor'

const multiply = (x, y) => x * y
const times3 = curryN(2, multiply)(3)

times3(5) // 15

0-arity functions

import { curryN } from 'conductor'

function multiply() {
  return arguments[0] * arguments[1]
}
multiply.length // 0
curryN(2, multiply).length // 2
const times3 = curryN(2, multiply)(3)

times3(5) // 15

Last updated