New:Socket for Asana Is Now Available.Learn more
Get Started

iterable-ops

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iterable-ops

Lazy utility functions for sync and async iterables — map, filter, take, chunk, zip, flatten

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

iterable-ops

Lazy utility functions for sync and async iterables — map, filter, take, chunk, zip, flatten

Install

npm install iterable-ops

Usage

import {map, filter, take, chunk, zip, flatten, unique} from 'iterable-ops';

[...map([1, 2, 3], x => x * 2)];
//=> [2, 4, 6]

[...filter([1, 2, 3, 4], x => x % 2 === 0)];
//=> [2, 4]

[...take([1, 2, 3, 4, 5], 3)];
//=> [1, 2, 3]

[...chunk([1, 2, 3, 4, 5], 2)];
//=> [[1, 2], [3, 4], [5]]

[...zip([1, 2], ['a', 'b'])];
//=> [[1, 'a'], [2, 'b']]

[...flatten([[1, 2], [3, [4]]])];
//=> [1, 2, 3, [4]]

[...unique([1, 2, 2, 3, 3])];
//=> [1, 2, 3]

All functions are lazy — they use generators and only compute values as they are consumed.

API

map(iterable, function_)

Yields function_(item) for each item.

filter(iterable, function_)

Yields items where function_(item) is truthy.

take(iterable, count)

Yields the first count items, then stops.

drop(iterable, count)

Skips the first count items, then yields the rest.

chunk(iterable, size)

Yields arrays of size items. The last chunk may be smaller.

zip(...iterables)

Yields arrays of parallel items from each iterable. Stops at the shortest.

flatten(iterable, depth?)

Yields items from nested iterables, flattening up to depth levels. Default: 1.

unique(iterable)

Yields only the first occurrence of each value.

mapAsync(iterable, function_)

Async version of map for async iterables.

filterAsync(iterable, function_)

Async version of filter for async iterables.

  • map-extras - Utility functions for JavaScript Map

License

MIT

Keywords

iterable

FAQs

Package last updated on 16 Feb 2026

Related posts