Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fjl-curry

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fjl-curry

[![Build Status](https://travis-ci.org/functional-jslib/fjl-curry.png)](https://travis-ci.org/functional-jslib/fjl-curry) [![GitHub version](https://badge.fury.io/gh/functional-jslib%2Ffjl-curry.svg)](http://badge.fury.io/gh/functional-jslib%2Ffjl-curry)

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status GitHub version NPM version Dependencies

fjl-curry

Basic curry implementations; One for strict currying (based on function's length property) and arbitrary currying for currying up-to a user defined number of arguments; 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
``` (platform feature).

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

Keywords

FAQs

Package last updated on 07 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc