Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Usage

import * as mod from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/iterable.ts";

The Iterable module contains utilities for working with the Iterable algebraic data type. Iterable is a lazy, synchronous, and native structure defined by ECMAScript that represents a sequence of values that can be iterated over.

Any data structure that implements the Iterable interface (Array, Map, Set, etc.) can use the iterable methods contained here. The module provides functional programming utilities for transforming, filtering, and combining iterables in a lazy, memory-efficient manner.

⚠️ Important Considerations:

  • Iterables can generate infinite sequences, potentially causing the runtime to hang if drained completely
  • Many iterables use generators which cannot be easily cloned, making chaining operations resource-intensive
  • Use these combinators with care, especially with potentially infinite iterables

§Variables

ApplicableIterable

The canonical implementation of Applicable for Iterable. It contains the methods wrap, apply, and map.

bind

Bind a value from an Iterable to a name for use in subsequent computations. This is useful for chaining multiple operations that depend on previous results.

bindTo

Bind a value to a specific name in an Iterable computation. This is useful for creating named intermediate values.

FilterableIterable

The canonical implementation of Filterable for Iterable. It contains the methods filter, filterMap, partition, and partitionMap.

FlatmappableIterable

The canonical implementation of Flatmappable for Iterable. It contains the methods wrap, apply, map, and flatmap.

FoldableIterable

The canonical implementation of Foldable for Iterable. It contains the method fold.

MappableIterable

The canonical implementation of Mappable for Iterable. It contains the method map.

tap

Execute a side effect on each element of an Iterable and return the original Iterable unchanged.

WrappableIterable

The canonical implementation of Wrappable for Iterable. It contains the method wrap.

§Functions

apply

Apply functions from an Iterable to values from another Iterable. This creates the cartesian product of functions and values.

clone

Create a cloneable version of an Iterable. This caches the results of iteration, allowing the iterable to be consumed multiple times. Note: This can be memory-intensive for large or infinite iterables.

collect

Collect all values of an Iterable into an array.

combine

Combine two Iterables by concatenating their elements.

filter

Filter an Iterable to only include elements that satisfy a predicate.

filterMap

Filter and map an Iterable simultaneously. Elements that result in None are filtered out, while Some values are unwrapped.

flatmap

Chain computations by applying a function that returns an Iterable to each element, then flattening the results.

fold

Fold an Iterable into a single value using a reducer function and initial value.

forEach

Execute a side effect for each element of an Iterable.

getCombinable

Create a Combinable instance for Iterable.

getInitializable

Create an Initializable instance for Iterable.

getShowable

Create a Showable instance for Iterable given a Showable instance for its elements.

init

Create an empty Iterable.

iterable

Create an Iterable from a function that returns an Iterator.

map

Apply a function to each element of an Iterable.

partition

Partition an Iterable into two Iterables based on a predicate. The first contains elements that satisfy the predicate, the second contains elements that don't.

partitionMap

Partition an Iterable into two Iterables based on an Either result. Right values go to the first Iterable, Left values to the second.

range

Create an Iterable that yields a range of numbers.

repeat

Repeat an Iterable n times.

scan

Create an Iterable that yields accumulated values from a fold operation.

take

Take the first n elements from an Iterable.

takeUntil

Take elements from an Iterable until a predicate is satisfied. The element that satisfies the predicate is not included.

takeWhile

Take elements from an Iterable while a predicate is satisfied. Stops at the first element that doesn't satisfy the predicate.

wrap

Create an Iterable from a variable number of values.

§Interfaces

KindIterable

Specifies Iterable as a Higher Kinded Type, with covariant parameter A corresponding to the 0th index of any substitutions.