Iterable50
Constructors
emptyconstCreates an empty iterable that yields no elements.foreverconstRepeats an iterable without an upper bound.makeByconstCreates an iterable by applying a function to consecutive integers.ofconstCreates an iterable containing a single element.rangeconstReturns an iterable of integers starting at start and increasing by 1.repeatconstRepeats an iterable n times, yielding the full contents of self for each repetition.replicateconstReturns a Iterable containing a value repeated the specified number of times.unfoldconstGenerates an iterable by repeatedly applying a function that produces the next element and state.Guards
Getters
dropconstDrops a max number of elements from the start of an Iterable Details n is normalized to a non-negative integer.headconstGets the first element of a Iterable safely, or None if the Iterable is empty.headUnsafeconstGets the first element of an Iterable without returning an Option.sizeconstReturns the number of elements in a Iterable.takeconstKeeps only a max number of elements from the start of an Iterable, creating a new Iterable.takeWhileconstTakes the longest initial Iterable prefix for which all elements satisfy the specified predicate.Elements
cartesianconstZips this Iterable crosswise with the specified Iterable.cartesianWithconstZips this Iterable crosswise with the specified Iterable using the specified combiner.containsconstChecks whether an iterable contains a value using Effect's default Equal equivalence.containsWithconstReturns a function that checks if an Iterable contains a given value using a provided isEquivalent function.findFirstconstReturns the first element that satisfies the specified predicate, or None if no such element exists.findLastconstFinds the last element for which a predicate holds.forEachconstIterates over the Iterable, applying f to each element.someconstChecks whether a predicate holds true for some Iterable element.Mapping
Filtering
dedupeAdjacentconstDeduplicates adjacent elements that are identical.dedupeAdjacentWithconstDeduplicates adjacent elements that are identical using the provided isEquivalent function.filterconstFilters an iterable to only include elements that match a predicate.filterMapconstTransforms elements of an iterable using a function that returns a Result, keeping only successful values.filterMapWhileconstTransforms all elements of the Iterable for as long as the specified function succeeds.getFailuresconstReturns a lazy iterable containing the failure values from an iterable of Results, skipping successful results.getSomesconstRetrieves the Some values from an Iterable of Options.getSuccessesconstReturns a lazy iterable containing the success values from an iterable of Results, skipping failed results.Sequencing
flatMapconstApplies a function to each element in an Iterable and returns a new Iterable containing the concatenated mapped elements.flatMapNullishOrconstTransforms elements using a function that may return null or undefined, filtering out the null/undefined results.flattenconstFlattens an Iterable of Iterables into a single Iterable Example (Flattening nested iterables) ts import { Iterable } from "effect" // Flatten nested arrays const nested = [[1, 2], [3, 4], [5, 6]] const flat = Iterable.flatten(nested) console.log(Array.from(flat)) // [1, 2, 3, 4, 5, 6] // Flatten different iterable types const mixed: Array<Iterable<string>> = ["ab", "cd"] const flatMixed = Iterable.flatten(mixed) console.log(Array.from(flatMixed)) // ["a", "b", "c", "d"] // Flatten deeply nested (only one level) const deepNested = [[[1, 2]], [[3, 4]]] const oneLevelFlat = Iterable.flatten(deepNested) console.log(Array.from(oneLevelFlat).map((arr) => Array.from(arr))) // [[1, 2], [3, 4]] (still contains arrays) // Empty iterables are handled correctly const withEmpty = [[1, 2], [], [3, 4], []] const flatWithEmpty = Iterable.flatten(withEmpty) console.log(Array.from(flatWithEmpty)) // [1, 2, 3, 4] Combining
appendconstAppends an element to the end of an Iterable, creating a new Iterable.appendAllconstConcatenates two iterables, combining their elements.intersperseconstPlaces a separator between members of an Iterable.prependconstPrepends an element to the front of an Iterable, creating a new Iterable.prependAllconstPrepends the specified prefix iterable to the beginning of the specified iterable.Converting
Folding
countByconstComputes how many elements of the iterable pass the given predicate.reduceconstReduces an iterable to a single value by applying a function to each element and accumulating the result.scanconstReduces an Iterable from the left, keeping all intermediate results instead of only the final result.