This package has been deprecated

Author message:

Deprecated in favor of 'fjl' (contains same implementations of curry (albeit more sturdy ones)).

fjl-curry

1.0.2 • Public • Published

Build Status GitHub version NPM version Dependencies

fjl-curry

curry implementations; One for strict currying (based on function's length property) and 4 implementations for arbitrary currying up-to a user defined length; E.g.,

For default arity (strict) based currying:

import {curry} from 'fjl-curry';

const add$ = (a, b) => a + b;
    add = curry(add$);

add(1)(1) === 2 // ...

For arbitrary currying:

import {curry2, curry3, curry4, curry5, curryN} from 'fjl-curry';

const add = (...args) => args.reduce((agg, arg) => agg + arg, 0),
    add2 = curry2(add),
    add3 = curry3(add),
    add4 = curry4(add),
    add5 = curry5(add),
    add6 = curryN(6, add),
    otherAdd2 = curryN(2, add); // same as `add2`

    add2(1)(2) === 3; // true
    add3(1)(2)(3) === 6; // ...
    add4(1)(2)(3)(4) === 10; // ...
    add5(1)(2)(3)(4)(5) === 15; // ...
    add6(1)(2)(3)(4)(5)(6) === 15; // ...
    otherAdd2(1)(2) === 3; // true

Docs:

Jsdocs: https://functional-jslib.github.io/fjl-curry/module-fjlCurry.html

Usage:

Importing the module:

Using es2015 module imports:

import {curry...} from 'fjl-curry'

Using commonjs modules.

const {curry} = require('fjl-curry');

Note: The module is also exported to 'amd', 'iife', and 'umd' formats ( look inside of './dist' for the export you want (in this case).

Example usage:

import {curry} from 'fjl-curry';

const someOp = curry((options, initialValue) => {
    // ...
}),

somePreparedOp = someOp(initialOptions);

// Get value of prepared op somewhere else...
somePreparedOp('some-initial-value'); // wallah!  Uses initially set options!

Installation

  • yarn add fjl-curry or
  • npm install fjl-curry

Members

  • curry (fn, ...initialArgs) : Function - Curries a function based on it's defined arity - *functions length property; Note: Functions length property shows the number of defined parameters by default though the contained length value doesn't count the rest params parameter; E.g.,
    // Variadic part is not counted in arity
    ((x, ...rest) => {}).length === 1

Example usage:

    // Another example
    const add3 = (a, b, c) => a + b + c,
        add3$ = curry(add3);
    add3$(1)(2)(3) === 6 //
  • curryN (n, fn, ...initialArgs) : Function - Curries a function up to n number of parameters; E.g., will curry the given function until n number of arguments are received; E.g.,
    const _add3 = (...args) => args.reduce((agg, arg) => agg + arg, 0),
        add3 = curry(_add3),
        add2 = add3(98),
        add1 = add2(1);

    add1(1) === 98 + 1 + 1 // true
  • curry2 (fn) : Function - Curries function up-to 2 or more arguments.
  • curry3 (fn) : Function - Curries function up-to 3 or more arguments.
  • curry4 (fn) : Function - Curries function up-to 4 or more arguments.
  • curry5 (fn) : Function - Curries function up-to 5 or more arguments.

Testing

  • yarn test or
  • npm test

License:

BSD

Package Sidebar

Install

npm i fjl-curry

Weekly Downloads

10

Version

1.0.2

License

BSD-3-Clause

Last publish

Collaborators

  • elycruz