README.md

May 28, 2020 Ā· View on GitHub

compose-tiny

A very tiny and fast compose function.

CircleCI Codecov npm bundle size code style: prettier

Function composition is an act or mechanism to combine simple functions to build more complicated ones.

compose-tiny aims to provide a simple function for composition at the smallest possible size and the fasted possible speed. It's TypeScript friendly too!

Installation

npm install compose-tiny

Usage

const compose = require('compose-tiny');

const add = x => x + 2;
const sqr = x => x ** 2;

const blastOff = compose(
  x => `šŸš€ ${x} šŸš€`
  sqr,
  add
);

blastOff(2);

Output:

šŸš€ 16 šŸš€

Multiple Arguments

The first function in the composition can take multiple arguments.

const compose = require('compose-tiny');

const add = x => x + 2;
const sqr = x => x ** 2;

const blastOff = compose(
  sqr,
  add,
  (x, y, z) => (x + y) * z
);

blastOff(1, 2, 4);

Performance

NOTE: bundlephobia measures all package files

NAMEOPS/SECRELATIVE MARGIN OF ERRORSAMPLE SIZEBUNDLE SIZE
compose-tiny1108,413± 0.72%187112 B
squad105,070± 0.62%185517 B
just-compose46,964± 1.88%181334 B
chain-function22,556± 0.50%187341 B
compose-function20,817± 0.49%1861.2 kB
fj-compose8,581± 0.61%184334 B
compose-funcs356± 1.58%176594 B

To rerun this benchmark

node benchmark