https://github.com/danielkov/async-array
https://github.com/danielkov/async-array
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/danielkov/async-array
- Owner: danielkov
- Created: 2020-01-24T19:44:51.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T05:40:23.000Z (over 3 years ago)
- Last Synced: 2025-04-08T22:02:01.210Z (about 1 year ago)
- Language: TypeScript
- Size: 1.76 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Async Iterators
A chainable reference implementation of lazy iterators.
## Examples
Works with any iterable.
```ts
import * as iterators from './src/index';
const map = curry(iterators.map);
const filter = curry(iterators.map);
const cubicPar = compose(
filter((x: number) => x % 2 === 0),
map((x: number) => x * x * x),
take(5),
);
const sequence = iterators.numericSequence(1, 20);
const test = cubicPar(sequence);
expect(iterators.getValue(test)).toStrictEqual([8, 64, 216, 512, 1000]);
```
Anything that implements `Symbol.iterable`.
```ts
import * as iterators from './src/index';
const reduce = curry(iterators.reduce);
const filter = curry(iterators.filter);
const testPipe = compose(
filter(char => char !== 't'),
reduce((acc, cur) => acc + cur),
);
const test = 'testtesttest';
const testValue = testPipe(test);
expect(iterators.getValue(testValue)).toBe('eseses');
```
Works well with functional libraries that do `curry` and `compose`.