Functional library for JavaScript and TypeScript.
npm install --save funcl.js
or
yarn add funcl.js
((y -> z), (x -> y), ..., (a -> b)) -> a -> z
Performs right-to-left function composition. The all arguments must be unary.
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
((a -> b), (c -> d), ..., (y -> z)) -> a -> z
Performs left-to-right function composition. The all arguments must be unary.
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