Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/iter/mod.ts

A bunch of utilities for working with iterables, many inspired by the native array methods.
Latest
import * as iter from "https://deno.land/x/iter@v3.2.3/mod.ts";

Variables

Curried functions. Note that only functions which take an iterable as a first argument, and accept more than one argument, are curried.

License of the module

Version of the module

Functions

Finds the average of all items in it.

Splits an iterable into evenly sized chunks. See @sindresorhus/chunkify

Lazily flattens a nested iterable completely, such that none of its yielded values are iterable.

Combines two or more iterables.

Creates an endless iterable of a constant value.

Creates an endless iterable from the return values of a function.

Creates an iterable from IteratorResults returned by a function.

Creates an iterable over a string's char codes.

Creates an iterable over a string's chars.

Constructs an iterable from an iterable of its results.

Creates an endless iterable of incrementing numbers.

Creates an endless iterable of pseudorandom numbers.

Creates an iterable over an inclusive range of numbers.

Returns a new iterable containing the items of it except the first n items.

Returns a new iterable which skips items from it until f returns true. true.

Returns a new iterable which skips items from it while f returns true. true.

Determines whether the specified callback function returns true for all items in an iterable.

Returns the items of an iterable that meet the condition specified in a callback function.

Returns the value of the first item in the iterable where predicate is true, and undefined otherwise.

Returns the index of the first item in the iterable where predicate is true, and -1 otherwise.

Lazily flattens a nested iterable to a given depth. Similar to Array.prototype.flat

Lazily calls a defined callback function for each element of an iterable, and returns a new flattened iterable of the results by one level.

Performs the specified action for each item in an iterable, consuming the iterable in the process.

Strips and fuses an iterable, such that any results including and after a result with { done: true } are ignored. In the current implementation of most functions, both of these behaviours already happen, so generally this is only necessary when it is the only operation being applied.

Determines whether an iterable includes a certain element, returning true or false as appropriate.

Converts an iterable into a series of pairs of indices and values. Similar to Array.prototype.entries or rust's iter.enumerate().

Performs the specified action for each item in an iterable when the returned iterable is iterated over. Like forEach | forEach but non-consuming.

Lazily calls a defined callback function for each element of an iterable, and returns a new iterable of the results.

Finds the norm of it (distance from the origin).

Creates a new iterable containing tuples of each element of it1 and it2.

Generates a peekable iterator from the provided iterable (See Peekable). Note that unlike other transformers, this returns an extended IterableIterator rather than an iterable. Inspired by Rust's std::iter::Peekable.

Finds the product of all items in it.

Calls the specified callback function for all the items in an iterable. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

Makes an iterable remember. Each time it is iterated over it will yield the same results.

Determines whether the specified callback function returns true for any item in an iterable.

Finds the sum of all items in it.

Returns a new iterable containing the first n items of it.

Returns a new iterable which yields while f returns true.

Returns a new iterable which yields until f returns true.

Interfaces

endlessFrom | endlessFrom generator callback.

from | from generator callback.

A curried version of an IterFunction. All non-generator functions in fp.ts are either of type IterFunction or UniaryIterFunction.

The same as the Iterable type, but the iterator implementation is iterable.

Iterable predicate callback.

Type for all iterable functions in the library.

An iterator that defines a peeking mechanism. Inspired by Rust's std::Iter::Peekable

Generic predicate callback.

reduce | reduce accumulator callback.

reduce | reduce stop callback.

Type Aliases

Alias for an IterFunction which accepts no arguments accept an iterable.

An alias for a special case of UniaryIterTransformer for when the result is an iterable.