1.0.0 • Published 3 years ago

ts-compose v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

ts-compose

((y → z), (x → y), …, (o → p), ((a, b, …, n) → o)) → ((a, b, …, n) → z)

Performs right-to-left function composition.

import { compose } from 'ts-compose';

const addOne = (x: number) => x + 1;
const double = (x: number) => x * 2;

compose(Math.abs, addOne, double)(-4) //=> 7

const toUpper = (x: string) => x.toUpperCase();
const classyGreeting = (firstName: string, lastName: string) => "The name's " + lastName + ", " + firstName + " " + lastName
const yellGreeting = compose(toUpper, classyGreeting);
yellGreeting('James', 'Bond'); //=> "THE NAME'S BOND, JAMES BOND"

Try it