Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hipstersmoothie/compose-tiny
A very tiny and fast compose function.
https://github.com/hipstersmoothie/compose-tiny
Last synced: about 1 month ago
JSON representation
A very tiny and fast compose function.
- Host: GitHub
- URL: https://github.com/hipstersmoothie/compose-tiny
- Owner: hipstersmoothie
- License: mit
- Created: 2018-09-28T06:30:39.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T19:14:34.000Z (about 2 years ago)
- Last Synced: 2025-01-02T03:38:14.933Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 2.06 MB
- Stars: 46
- Watchers: 3
- Forks: 2
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - compose-tiny - A very tiny and fast compose function. (JavaScript)
README
![]()
compose-tiny
A very tiny and fast compose function.
[](https://circleci.com/gh/hipstersmoothie/compose-tiny/tree/master) [](https://codecov.io/gh/hipstersmoothie/compose-tiny) [](https://www.npmjs.com/package/compose-tiny) [](https://www.npmjs.com/package/compose-tiny) [](https://github.com/prettier/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
```sh
npm install compose-tiny
```## Usage
```js
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:
```sh
🚀 16 🚀
```## Multiple Arguments
The first function in the composition can take multiple arguments.
```js
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](https://bundlephobia.com/result?p=compose-tiny) |
| squad | 105,070 | ± 0.62% | 185 | [517 B](https://bundlephobia.com/result?p=squad) |
| just-compose | 46,964 | ± 1.88% | 181 | [334 B](https://bundlephobia.com/result?p=just-compose) |
| chain-function | 22,556 | ± 0.50% | 187 | [341 B](https://bundlephobia.com/result?p=chain-function) |
| compose-function | 20,817 | ± 0.49% | 186 | [1.2 kB](https://bundlephobia.com/result?p=compose-function) |
| fj-compose | 8,581 | ± 0.61% | 184 | [334 B](https://bundlephobia.com/result?p=fj-compose) |
| compose-funcs | 356 | ± 1.58% | 176 | [594 B](https://bundlephobia.com/result?p=compose-funcs) |To rerun this benchmark
```sh
node benchmark
```