ts-compose
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i ts-compose

    Weekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    5.94 kB

    Total Files

    8

    Last publish

    Collaborators

    • binjospookie