ts-compose
v1.0.0
Published
Performs right-to-left function composition.
Downloads
27
Maintainers
Readme
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"