Skip to content

Generator ​

Functions to manipulate JavaScript generators in a functional and type-safe way. Generators allow you to process data sequences lazily, computing values only when they are needed.

How to import? ​

The library exposes the DGenerator and G namespaces from the main entry or via direct import (tree-shaking friendly), which lets you only load what you need.

typescript
import { DGenerator, G } from "@duplojs/utils";
import * as DGenerator from "@duplojs/utils/generator";
import * as G from "@duplojs/utils/generator";

Execution ​

execute ​

Executes a generator and returns all its values in an array.

createExternalAsyncGenerator ​

Creates an externally controlled async generator.

Iteration ​

loop ​

Iterates over each element of a generator with a callback function.

asyncLoop ​

Iterates over each element of a generator with an async callback function.

Transformation ​

map ​

Transforms each element of a generator by applying a function.

asyncMap ​

Transforms each element of a generator with an async function.

concat ​

Concatenates multiple iterables into a single generator.

asyncConcat ​

Concatenates sync or async iterables into a single async generator.

flat ​

Flattens nested iterables into a single generator.

asyncFlat ​

Flattens synchronous or asynchronous iterables into an async generator.

chunk ​

Splits an iterable into fixed-size chunks and returns a generator of arrays.

Filtering ​

filter ​

Filters the elements of a generator according to a predicate.

asyncFilter ​

Filters the elements of a generator with an async predicate.

Grouping ​

group ​

Groups iterable elements into an object of arrays by group name.

asyncGroup ​

Asynchronous grouping version for async iterables.

Reduction ​

reduce ​

Reduces a generator to a single value by applying an accumulator function.

asyncReduce ​

Reduces a generator to a single value with an async accumulator function.

Released under the MIT license.