funcl.js
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

funcl.js

npm Version License Bundle size Bundle size Build Status

Functional library for JavaScript and TypeScript.

Installation

npm install --save funcl.js

or

yarn add funcl.js

API

compose

((y -> z), (x -> y), ..., (a -> b)) -> a -> z

Performs right-to-left function composition. The all arguments must be unary.

Example

import { compose } from "funcl.js";
import { compose } from "funcl.js/esm"; // ES6 module

const add = (num1: number) => (num2: number) => num1 + num2;
const multiple = (num1: number) => (num2: number) => num1 * num2;
const getResult = (num: number) => `Result: ${num}`;

const composed = compose(getResult, multiple(3), add(10));
composed(4); // => Result: 42

pipe

((a -> b), (c -> d), ..., (y -> z)) -> a -> z

Performs left-to-right function composition. The all arguments must be unary.

Example

import { pipe } from "funcl.js";
import { pipe } from "funcl.js/esm"; // ES6 module

const add = (num1: number) => (num2: number) => num1 + num2;
const multiple = (num1: number) => (num2: number) => num1 * num2;
const getResult = (num: number) => `Result: ${num}`;

const pipeline = pipe(multiple(3), add(10), getResult);
pipeline(4); // => Result: 22

Package Sidebar

Install

npm i funcl.js

Weekly Downloads

1

Version

0.1.3

License

MIT

Unpacked Size

10.7 kB

Total Files

19

Last publish

Collaborators

  • neketabrain