https://github.com/simplesmiler/thru
Type-safe operator for chaining
https://github.com/simplesmiler/thru
chaining typescript
Last synced: 8 days ago
JSON representation
Type-safe operator for chaining
- Host: GitHub
- URL: https://github.com/simplesmiler/thru
- Owner: simplesmiler
- Created: 2020-06-25T20:21:57.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-26T00:05:43.000Z (about 6 years ago)
- Last Synced: 2025-09-24T11:31:23.386Z (9 months ago)
- Topics: chaining, typescript
- Language: TypeScript
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @simplesmiler/thru
[](https://www.npmjs.com/package/@simplesmiler/thru)
[](https://github.com/simplesmiler/thru#readme)
> Type-safe operator for chaining
- Allows function calls to follow the data flow instead of being nested
- Does not require pre-chain wrapping and post-chain unwrapping
- Does not require explicit-er types than usual
- Promotes code minification due to tree shaking and name mangling
Inspired by:
- Lodash.thru: https://lodash.com/docs/
- Bind operator proposal: https://github.com/tc39/proposal-bind-operator
- Pipeline operator proposal: https://github.com/tc39/proposal-pipeline-operator
- Do notation from Haskell: https://en.wikibooks.org/wiki/Haskell/do_notation
- Discussion over at https://esdiscuss.org/topic/array-prototype-tap
## Install
```sh
npm install @simplesmiler/thru
```
## Use
```js
import { thru, tap } from '@simplesmiler/thru';
import { flatten } from 'lodash/fp';
const result = [1, 2, 3]
.map((x) => [x, x * 2])
[thru](flatten)
[thru]((list) => list.slice().sort((a, b) => a - b))
[tap]((sorted) => console.log('DEBUG:', sorted))
.join(', ')
[thru]((text) => `Computed numbers: ${text}`);
```
## License
Copyright © 2020 [Denis Karabaza ](https://github.com/simplesmiler).
This project is ISC licensed.