https://github.com/evanhahn/iterpal
a friendly collection of utilities for iterables
https://github.com/evanhahn/iterpal
iterable iterator javascript
Last synced: 4 months ago
JSON representation
a friendly collection of utilities for iterables
- Host: GitHub
- URL: https://github.com/evanhahn/iterpal
- Owner: EvanHahn
- License: mit
- Created: 2019-05-06T01:19:41.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2024-05-26T12:51:26.000Z (about 1 year ago)
- Last Synced: 2025-02-28T09:16:39.591Z (5 months ago)
- Topics: iterable, iterator, javascript
- Language: TypeScript
- Homepage:
- Size: 720 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Iterpal
Iterable tools for JavaScript.
## Installation
Iterpal is available from the npm registry:
```sh
npm install iterpal
```With Deno:
```typescript
import { filter, map } from "https://evanhahn.com/tape/iterpal/0.4.0/mod.ts";
```## Documentation
[API documentation](https://doc.deno.land/https://evanhahn.com/tape/iterpal/0.4.0/mod.ts)
## Use cases
- Get helpful utilities not in the standard library.
`last` is a simple one, but there are many others:
```javascript
import { last } from "iterpal";
last("iterpal!");
// => "!"
```- Use collection utilities like `map` and `filter` with any iterable.
That includes arrays, strings,
[sets](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set),
[maps](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map),
[typed arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray),
[buffers](https://nodejs.org/api/buffer.html#buffer_buffer),
[streams](https://nodejs.org/api/stream.html), (async)
[generators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator),
or
[anything implementing the interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol).```javascript
import { filter } from "iterpal";
const letterOs = filter("foo", (c) => c === "o");
```- Take advantage of lazy iteration.
Many of Iterpal's functions return lazily, which can help you maintain a
functional style while still enjoying performance benefits.```javascript
import { map, take } from "iterpal";// The second operation is faster because
// it iterates over fewer values.
lotsOfNumbers.map(square).slice(10);
lotsOfNumbers.slice(10).map(square);// These two operations are basically equivalent.
take(map(lotsOfNumbers, square), 10);
map(take(lotsOfNumbers, 10), square);
```