funcl.js
v0.1.3
Published
Functional library for JavaScript and TypeScript
Downloads
4
Maintainers
Readme
funcl.js
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