1.0.6 • Published 5 years ago
@lpvua/curry v1.0.6
curry
Tiny function which returns curried equivalent of provided function
Installation
$ npm install @lpvua/curry
Or add it into HTML
<script type="text/javascript" src="https://unpkg.com/@lpvua/curry"></script>
API
curry(fn, arity)
Creates curried function
Properties
fn
- Function to curryarity
- (optional) arity number. Is needed when provided function has any number of arguments
example
import curry from '@lpvua/curry'
const sum = (a, b, c) => a + b + c
const curriedSum = curry(sum)
curriedSum(2)(2, 3) // 7
curriedSum(2, 2, 3) // 7
curriedSum(2, 2)(3) // 7
curriedSum(2)(2)(3) // 7
const sumN = (...args) => args.reduce((a, b) => a + b)
const curriedSumN = curry(sumN, 3)
curriedSumN(2)(2, 3) // 7
curriedSumN(2, 2, 3) // 7
curriedSumN(2, 2)(3) // 7
curriedSumN(2)(2)(3) // 7