hipstersmoothie / compose-tiny

A very tiny and fast compose function.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

NAME OPS/SEC RELATIVE MARGIN OF ERROR SAMPLE SIZE BUNDLE SIZE
compose-tiny 1108,413 Β± 0.72% 187 112 B
squad 105,070 Β± 0.62% 185 517 B
just-compose 46,964 Β± 1.88% 181 334 B
chain-function 22,556 Β± 0.50% 187 341 B
compose-function 20,817 Β± 0.49% 186 1.2 kB
fj-compose 8,581 Β± 0.61% 184 334 B
compose-funcs 356 Β± 1.58% 176 594 B

To rerun this benchmark

node benchmark

About

A very tiny and fast compose function.

License:MIT License


Languages

Language:JavaScript 100.0%