@lpvua/curry

1.0.6 • Public • Published

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 curry
  • arity - (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

/@lpvua/curry/

    Package Sidebar

    Install

    npm i @lpvua/curry

    Weekly Downloads

    1

    Version

    1.0.6

    License

    ISC

    Unpacked Size

    10.8 kB

    Total Files

    9

    Last publish

    Collaborators

    • lpvua-pavlo