Skip to main content

Built and signed on GitHub Actions

♻️ Iterable and AsyncIterable utilities.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
4 months ago (0.3.3)
Coven Engineering Iterables logo

JSR JSR Score

♻️ Iterable and AsyncIterable utilities.

One of the places curried functions shine the most is with iterables. More often than not, mapping, filtering and so on is applied to multiple different iterables, which results in duplicated code.

@coven/iterables provides 2 modules, the default for synchronous iterables and then @coven/iterables/async for asynchronous iterables. All functions are curried to reduce code duplication, and they work with all iterables (generator functions, arrays, strings, Sets, Maps, etc.).

One of the key differences between this library and other similar collection handling libraries like say lodash, is the heavy use of iterators. At first glance they might looks slower because of their complexity, but in reality they produce a faster "perceived performance". This is because of the way iterables iteration work compared to plain arrays.

While array operation has to go over all items before going to the next function, iterables run all functions in each item and yields them:

const double = (value: number) => value * 2;
const next = (value: number) => value + 1;

// With array methods

[1, 2, 3, 4].map(double).map(next).forEach(console.log);
// 1. [2, 4, 6, 8] in memory the user is still waiting for output
// 2. [3, 5, 7, 9] in memory the user is still waiting for output
// 3. Logs 3
// 4. Logs 5
// 5. Logs 7
// 6. Logs 9

// With iterables functions

import { forEach, map } from "@coven/iterables";

// [1, 2, 3, 4] |> map(double) |> map(next) |> forEach(console.log);
forEach(console.log)(map(next)(map(double)([1, 2, 3, 4])));
// 1. 2 → 3 → Logs 3
// 2. 4 → 5 → Logs 5
// 3. 6 → 7 → Logs 7
// 4. 8 → 9 → Logs 9

Like all Coven Engineering libraries, it has 100% test coverage and it's built in top of modern tech compatible with all JavaScript runtimes.

Example

import { map } from "@coven/iterables";

const double = (multiplier: number) => multiplier * 2;
const doubles = map(double);

doubles([13, 42]); // Yields [26, 84]
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add jsr:@coven/iterables

Import symbol

import * as iterables from "@coven/iterables";

---- OR ----

Import directly with a jsr specifier

import * as iterables from "jsr:@coven/iterables";

Add Package

npx jsr add @coven/iterables

Import symbol

import * as iterables from "@coven/iterables";

Add Package

yarn dlx jsr add @coven/iterables

Import symbol

import * as iterables from "@coven/iterables";

Add Package

pnpm dlx jsr add @coven/iterables

Import symbol

import * as iterables from "@coven/iterables";

Add Package

bunx jsr add @coven/iterables

Import symbol

import * as iterables from "@coven/iterables";