/**
* Works with JavaScript values that implement `[Symbol.iterator]`.
*
* Iterables include arrays, strings, generators, sets, and custom lazy
* sequences. The helpers in this module let code transform, search, group, and
* fold iterable values while preserving the input as an iterable instead of
* forcing an array first.
*
* @stability stable
* @since 2.0.0
*/
import type { NonEmptyArray } from "./Array.ts";
import type { Option } from "./Option.ts";
import type * as Record from "./Record.ts";
import type { Result } from "./Result.ts";
import type { NoInfer } from "./Types.ts";
/**
* Creates an iterable by applying a function to consecutive integers.
*
* **Details**
*
* The function is called with each index starting from `0`. If a length is
* provided, it is rounded down and normalized to at least `1`, with `NaN`
* treated as `1`. If no length is specified, the iterable is infinite.
*
* **Example** (Generating values by index)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Generate first 5 even numbers
* const evens = Iterable.makeBy((n) => n * 2, { length: 5 })
* Array.from(evens) // => [0, 2, 4, 6, 8]
*
* // Generate squares
* const squares = Iterable.makeBy((n) => n * n, { length: 4 })
* Array.from(squares) // => [0, 1, 4, 9]
*
* // Infinite sequence (be careful when consuming!)
* const naturals = Iterable.makeBy((n) => n)
* const first10 = Iterable.take(naturals, 10)
* Array.from(first10) // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
* ```
*
* @stability stable
* @category constructors
* @since 2.0.0
*/
export declare const makeBy: (f: (i: number) => A, options?: {
readonly length?: number;
}) => Iterable;
/**
* Returns an iterable of integers starting at `start` and increasing by `1`.
*
* **Details**
*
* When `end` is provided and `start <= end`, both endpoints are included. When
* `end` is omitted, the iterable is unbounded. When `start > end`, the
* iterable contains only `start`.
*
* **Example** (Creating a range)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* Array.from(Iterable.range(1, 3)) // => [1, 2, 3]
* ```
*
* @stability stable
* @category constructors
* @since 2.0.0
*/
export declare const range: (start: number, end?: number) => Iterable;
/**
* Returns a `Iterable` containing a value repeated the specified number of times.
*
* **Details**
*
* `n` is rounded down and normalized to an integer greater than or equal to
* `1`. `NaN` is treated as `1`.
*
* **Example** (Repeating a value)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* Array.from(Iterable.replicate("a", 3)) // => ["a", "a", "a"]
* ```
*
* @stability stable
* @category constructors
* @since 2.0.0
*/
export declare const replicate: {
/**
* Returns a `Iterable` containing a value repeated the specified number of times.
*
* **Details**
*
* `n` is rounded down and normalized to an integer greater than or equal to
* `1`. `NaN` is treated as `1`.
*
* **Example** (Repeating a value)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* Array.from(Iterable.replicate("a", 3)) // => ["a", "a", "a"]
* ```
*
* @stability stable
* @category constructors
* @since 2.0.0
*/
(n: number): (a: A) => Iterable;
/**
* Returns a `Iterable` containing a value repeated the specified number of times.
*
* **Details**
*
* `n` is rounded down and normalized to an integer greater than or equal to
* `1`. `NaN` is treated as `1`.
*
* **Example** (Repeating a value)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* Array.from(Iterable.replicate("a", 3)) // => ["a", "a", "a"]
* ```
*
* @stability stable
* @category constructors
* @since 2.0.0
*/
(a: A, n: number): Iterable;
};
/**
* Repeats an iterable `n` times, yielding the full contents of `self` for each
* repetition.
*
* **When to use**
*
* Use to repeat an iterable's contents a specific number of times.
*
* **Details**
*
* The result is lazy. `n` is rounded down and normalized to at least `1`, with
* `NaN` treated as `1`. Each repetition obtains a new iterator from `self`.
*
* @see {@link forever} for repeating without an upper bound
* @see {@link replicate} for repeating a single value
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const repeat: {
/**
* Repeats an iterable `n` times, yielding the full contents of `self` for each
* repetition.
*
* **When to use**
*
* Use to repeat an iterable's contents a specific number of times.
*
* **Details**
*
* The result is lazy. `n` is rounded down and normalized to at least `1`, with
* `NaN` treated as `1`. Each repetition obtains a new iterator from `self`.
*
* @see {@link forever} for repeating without an upper bound
* @see {@link replicate} for repeating a single value
* @stability stable
* @category constructors
* @since 4.0.0
*/
(n: number): (self: Iterable) => Iterable;
/**
* Repeats an iterable `n` times, yielding the full contents of `self` for each
* repetition.
*
* **When to use**
*
* Use to repeat an iterable's contents a specific number of times.
*
* **Details**
*
* The result is lazy. `n` is rounded down and normalized to at least `1`, with
* `NaN` treated as `1`. Each repetition obtains a new iterator from `self`.
*
* @see {@link forever} for repeating without an upper bound
* @see {@link replicate} for repeating a single value
* @stability stable
* @category constructors
* @since 4.0.0
*/
(self: Iterable, n: number): Iterable;
};
/**
* Repeats an iterable without an upper bound.
*
* **When to use**
*
* Use to cycle a reusable iterable without an upper bound when a downstream
* consumer controls how many values are taken.
*
* **Gotchas**
*
* The returned iterable is lazy and should usually be bounded with `take` or
* another terminating consumer before materializing it.
*
* @see {@link repeat} for repeating an iterable a specific number of times
* @see {@link take} for bounding the unbounded result before materializing it
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const forever: (self: Iterable) => Iterable;
/**
* Takes a record and returns an Iterable of tuples containing its keys and values.
*
* **Example** (Converting a record to entries)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const x = { a: 1, b: 2, c: 3 }
* Array.from(Iterable.fromRecord(x)) // => [["a", 1], ["b", 2], ["c", 3]]
* ```
*
* @stability stable
* @category converting
* @since 2.0.0
*/
export declare const fromRecord: (self: Readonly>) => Iterable<[K, A]>;
/**
* Prepends an element to the front of an `Iterable`, creating a new `Iterable`.
*
* **Example** (Prepending an element)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [2, 3, 4]
* const withOne = Iterable.prepend(numbers, 1)
* Array.from(withOne) // => [1, 2, 3, 4]
*
* // Works with any iterable
* const letters = "abc"
* const withZ = Iterable.prepend(letters, "z")
* Array.from(withZ) // => ["z", "a", "b", "c"]
* ```
*
* @stability stable
* @category combining
* @since 2.0.0
*/
export declare const prepend: {
/**
* Prepends an element to the front of an `Iterable`, creating a new `Iterable`.
*
* **Example** (Prepending an element)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [2, 3, 4]
* const withOne = Iterable.prepend(numbers, 1)
* Array.from(withOne) // => [1, 2, 3, 4]
*
* // Works with any iterable
* const letters = "abc"
* const withZ = Iterable.prepend(letters, "z")
* Array.from(withZ) // => ["z", "a", "b", "c"]
* ```
*
* @stability stable
* @category combining
* @since 2.0.0
*/
(head: B): (self: Iterable) => Iterable;
/**
* Prepends an element to the front of an `Iterable`, creating a new `Iterable`.
*
* **Example** (Prepending an element)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [2, 3, 4]
* const withOne = Iterable.prepend(numbers, 1)
* Array.from(withOne) // => [1, 2, 3, 4]
*
* // Works with any iterable
* const letters = "abc"
* const withZ = Iterable.prepend(letters, "z")
* Array.from(withZ) // => ["z", "a", "b", "c"]
* ```
*
* @stability stable
* @category combining
* @since 2.0.0
*/
(self: Iterable, head: B): Iterable;
};
/**
* Prepends the specified prefix iterable to the beginning of the specified iterable.
*
* **Example** (Prepending another iterable)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* Array.from(Iterable.prependAll([1, 2], ["a", "b"])) // => ["a", "b", 1, 2]
* ```
*
* @stability stable
* @category combining
* @since 2.0.0
*/
export declare const prependAll: {
/**
* Prepends the specified prefix iterable to the beginning of the specified iterable.
*
* **Example** (Prepending another iterable)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* Array.from(Iterable.prependAll([1, 2], ["a", "b"])) // => ["a", "b", 1, 2]
* ```
*
* @stability stable
* @category combining
* @since 2.0.0
*/
(that: Iterable): (self: Iterable) => Iterable;
/**
* Prepends the specified prefix iterable to the beginning of the specified iterable.
*
* **Example** (Prepending another iterable)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* Array.from(Iterable.prependAll([1, 2], ["a", "b"])) // => ["a", "b", 1, 2]
* ```
*
* @stability stable
* @category combining
* @since 2.0.0
*/
(self: Iterable, that: Iterable): Iterable;
};
/**
* Appends an element to the end of an `Iterable`, creating a new `Iterable`.
*
* **When to use**
*
* Use to add one element after all elements of an iterable while keeping the
* result as a lazy `Iterable`.
*
* **Details**
*
* The result yields every element from `self` first, then yields `last` after
* `self` is exhausted.
*
* **Gotchas**
*
* If `self` is infinite or never completes, the appended element is never
* reached.
*
* **Example** (Appending an element)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3]
* Array.from(Iterable.append(numbers, 4)) // => [1, 2, 3, 4]
* ```
*
* @see {@link prepend} for adding one element before the existing elements
* @see {@link appendAll} for appending all elements from another iterable
*
* @stability stable
* @category combining
* @since 2.0.0
*/
export declare const append: {
/**
* Appends an element to the end of an `Iterable`, creating a new `Iterable`.
*
* **When to use**
*
* Use to add one element after all elements of an iterable while keeping the
* result as a lazy `Iterable`.
*
* **Details**
*
* The result yields every element from `self` first, then yields `last` after
* `self` is exhausted.
*
* **Gotchas**
*
* If `self` is infinite or never completes, the appended element is never
* reached.
*
* **Example** (Appending an element)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3]
* Array.from(Iterable.append(numbers, 4)) // => [1, 2, 3, 4]
* ```
*
* @see {@link prepend} for adding one element before the existing elements
* @see {@link appendAll} for appending all elements from another iterable
*
* @stability stable
* @category combining
* @since 2.0.0
*/
(last: B): (self: Iterable) => Iterable;
/**
* Appends an element to the end of an `Iterable`, creating a new `Iterable`.
*
* **When to use**
*
* Use to add one element after all elements of an iterable while keeping the
* result as a lazy `Iterable`.
*
* **Details**
*
* The result yields every element from `self` first, then yields `last` after
* `self` is exhausted.
*
* **Gotchas**
*
* If `self` is infinite or never completes, the appended element is never
* reached.
*
* **Example** (Appending an element)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3]
* Array.from(Iterable.append(numbers, 4)) // => [1, 2, 3, 4]
* ```
*
* @see {@link prepend} for adding one element before the existing elements
* @see {@link appendAll} for appending all elements from another iterable
*
* @stability stable
* @category combining
* @since 2.0.0
*/
(self: Iterable, last: B): Iterable;
};
/**
* Concatenates two iterables, combining their elements.
*
* **When to use**
*
* Use to lazily concatenate two iterables while preserving order, yielding all
* elements from `self` before `that`.
*
* **Details**
*
* The result is lazy. The iterator for `that` is not created or read until
* `self` is exhausted.
*
* **Gotchas**
*
* If `self` is infinite or never completes, `that` is never reached.
*
* **Example** (Concatenating iterables)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* Array.from(Iterable.appendAll([1, 2, 3], [4, 5, 6])) // => [1, 2, 3, 4, 5, 6]
*
* // Works with different iterable types
* const numbers = [1, 2]
* const letters = "abc"
* const mixed = Iterable.appendAll(numbers, letters)
* Array.from(mixed) // => [1, 2, "a", "b", "c"]
*
* // Lazy evaluation - only consumes what's needed
* const infinite = Iterable.range(1)
* const finite = [0, -1, -2]
* Array.from(Iterable.take(Iterable.appendAll(finite, infinite), 5)) // => [0, -1, -2, 1, 2]
* ```
*
* @see {@link append} for appending one value instead of another iterable
* @see {@link prependAll} for yielding another iterable before `self`
*
* @stability stable
* @category combining
* @since 2.0.0
*/
export declare const appendAll: {
/**
* Concatenates two iterables, combining their elements.
*
* **When to use**
*
* Use to lazily concatenate two iterables while preserving order, yielding all
* elements from `self` before `that`.
*
* **Details**
*
* The result is lazy. The iterator for `that` is not created or read until
* `self` is exhausted.
*
* **Gotchas**
*
* If `self` is infinite or never completes, `that` is never reached.
*
* **Example** (Concatenating iterables)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* Array.from(Iterable.appendAll([1, 2, 3], [4, 5, 6])) // => [1, 2, 3, 4, 5, 6]
*
* // Works with different iterable types
* const numbers = [1, 2]
* const letters = "abc"
* const mixed = Iterable.appendAll(numbers, letters)
* Array.from(mixed) // => [1, 2, "a", "b", "c"]
*
* // Lazy evaluation - only consumes what's needed
* const infinite = Iterable.range(1)
* const finite = [0, -1, -2]
* Array.from(Iterable.take(Iterable.appendAll(finite, infinite), 5)) // => [0, -1, -2, 1, 2]
* ```
*
* @see {@link append} for appending one value instead of another iterable
* @see {@link prependAll} for yielding another iterable before `self`
*
* @stability stable
* @category combining
* @since 2.0.0
*/
(that: Iterable): (self: Iterable) => Iterable;
/**
* Concatenates two iterables, combining their elements.
*
* **When to use**
*
* Use to lazily concatenate two iterables while preserving order, yielding all
* elements from `self` before `that`.
*
* **Details**
*
* The result is lazy. The iterator for `that` is not created or read until
* `self` is exhausted.
*
* **Gotchas**
*
* If `self` is infinite or never completes, `that` is never reached.
*
* **Example** (Concatenating iterables)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* Array.from(Iterable.appendAll([1, 2, 3], [4, 5, 6])) // => [1, 2, 3, 4, 5, 6]
*
* // Works with different iterable types
* const numbers = [1, 2]
* const letters = "abc"
* const mixed = Iterable.appendAll(numbers, letters)
* Array.from(mixed) // => [1, 2, "a", "b", "c"]
*
* // Lazy evaluation - only consumes what's needed
* const infinite = Iterable.range(1)
* const finite = [0, -1, -2]
* Array.from(Iterable.take(Iterable.appendAll(finite, infinite), 5)) // => [0, -1, -2, 1, 2]
* ```
*
* @see {@link append} for appending one value instead of another iterable
* @see {@link prependAll} for yielding another iterable before `self`
*
* @stability stable
* @category combining
* @since 2.0.0
*/
(self: Iterable, that: Iterable): Iterable;
};
/**
* Reduces an `Iterable` from the left, keeping all intermediate results instead of only the final result.
*
* **Example** (Tracking running results)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Running sum of numbers
* const numbers = [1, 2, 3, 4, 5]
* const runningSum = Iterable.scan(numbers, 0, (acc, n) => acc + n)
* Array.from(runningSum) // => [0, 1, 3, 6, 10, 15]
*
* // Build strings progressively
* const letters = ["a", "b", "c"]
* const progressive = Iterable.scan(letters, "", (acc, letter) => acc + letter)
* Array.from(progressive) // => ["", "a", "ab", "abc"]
*
* // Track maximum values seen so far
* const values = [3, 1, 4, 1, 5, 9, 2]
* const runningMax = Iterable.scan(values, -Infinity, Math.max)
* Array.from(runningMax) // => [-Infinity, 3, 3, 4, 4, 5, 9, 9]
* ```
*
* @stability stable
* @category folding
* @since 2.0.0
*/
export declare const scan: {
/**
* Reduces an `Iterable` from the left, keeping all intermediate results instead of only the final result.
*
* **Example** (Tracking running results)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Running sum of numbers
* const numbers = [1, 2, 3, 4, 5]
* const runningSum = Iterable.scan(numbers, 0, (acc, n) => acc + n)
* Array.from(runningSum) // => [0, 1, 3, 6, 10, 15]
*
* // Build strings progressively
* const letters = ["a", "b", "c"]
* const progressive = Iterable.scan(letters, "", (acc, letter) => acc + letter)
* Array.from(progressive) // => ["", "a", "ab", "abc"]
*
* // Track maximum values seen so far
* const values = [3, 1, 4, 1, 5, 9, 2]
* const runningMax = Iterable.scan(values, -Infinity, Math.max)
* Array.from(runningMax) // => [-Infinity, 3, 3, 4, 4, 5, 9, 9]
* ```
*
* @stability stable
* @category folding
* @since 2.0.0
*/
(b: B, f: (b: B, a: A) => B): (self: Iterable) => Iterable;
/**
* Reduces an `Iterable` from the left, keeping all intermediate results instead of only the final result.
*
* **Example** (Tracking running results)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Running sum of numbers
* const numbers = [1, 2, 3, 4, 5]
* const runningSum = Iterable.scan(numbers, 0, (acc, n) => acc + n)
* Array.from(runningSum) // => [0, 1, 3, 6, 10, 15]
*
* // Build strings progressively
* const letters = ["a", "b", "c"]
* const progressive = Iterable.scan(letters, "", (acc, letter) => acc + letter)
* Array.from(progressive) // => ["", "a", "ab", "abc"]
*
* // Track maximum values seen so far
* const values = [3, 1, 4, 1, 5, 9, 2]
* const runningMax = Iterable.scan(values, -Infinity, Math.max)
* Array.from(runningMax) // => [-Infinity, 3, 3, 4, 4, 5, 9, 9]
* ```
*
* @stability stable
* @category folding
* @since 2.0.0
*/
(self: Iterable, b: B, f: (b: B, a: A) => B): Iterable;
};
/**
* Checks whether an `Iterable` is empty.
*
* **Example** (Checking for emptiness)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* Iterable.isEmpty([]) // => true
* Iterable.isEmpty([1, 2, 3]) // => false
* ```
*
* @stability stable
* @category guards
* @since 2.0.0
*/
export declare const isEmpty: (self: Iterable) => self is Iterable;
/**
* Returns the number of elements in a `Iterable`.
*
* **Example** (Counting iterable elements)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3, 4, 5]
* Iterable.size(numbers) // => 5
*
* const empty = Iterable.empty()
* Iterable.size(empty) // => 0
*
* // Works with any iterable
* const letters = "hello"
* Iterable.size(letters) // => 5
*
* // Note: This consumes the entire iterable
* const range = Iterable.range(1, 100)
* Iterable.size(range) // => 100
* ```
*
* @stability stable
* @category getters
* @since 2.0.0
*/
export declare const size: (self: Iterable) => number;
/**
* Gets the first element of a `Iterable` safely, or `None` if the `Iterable` is empty.
*
* **Example** (Getting the first element)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 2, 3]
* Iterable.head(numbers) // => Option.some(1)
*
* const empty = Iterable.empty()
* Iterable.head(empty) // => Option.none()
*
* // Safe way to get first element
* const firstEven = Iterable.head(
* Iterable.filter([1, 3, 4, 5], (x) => x % 2 === 0)
* )
* firstEven // => Option.some(4)
*
* // Use with Option methods
* const doubled = Option.map(Iterable.head([5, 10, 15]), (x) => x * 2)
* doubled // => Option.some(10)
* ```
*
* @stability stable
* @category getters
* @since 2.0.0
*/
export declare const head: (self: Iterable) => Option;
/**
* Gets the first element of an `Iterable` without returning an `Option`.
*
* **When to use**
*
* Use when the `Iterable` is known to be non-empty and direct access to the
* first element is preferred over handling `Option.none`.
*
* **Gotchas**
*
* Throws if the `Iterable` is empty.
*
* **Example** (Getting the first element unsafely)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3]
* Iterable.headUnsafe(numbers) // => 1
*
* const letters = "hello"
* Iterable.headUnsafe(letters) // => "h"
*
* // Iterable.headUnsafe(Iterable.empty())
* // throws Error: "headUnsafe: empty iterable"
*
* // Use only when you're certain the iterable is non-empty
* const nonEmpty = Iterable.range(1, 10)
* Iterable.headUnsafe(nonEmpty) // => 1
* ```
*
* @stability stable
* @category getters
* @since 4.0.0
*/
export declare const headUnsafe: (self: Iterable) => A;
/**
* Keeps only a max number of elements from the start of an `Iterable`, creating a new `Iterable`.
*
* **Details**
*
* `n` is rounded down and normalized to a non-negative integer. `NaN` is
* treated as `0`.
*
* **Example** (Taking from the start)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3, 4, 5]
* const firstThree = Iterable.take(numbers, 3)
* Array.from(firstThree) // => [1, 2, 3]
*
* // Taking more than available returns all elements
* const firstTen = Iterable.take(numbers, 10)
* Array.from(firstTen) // => [1, 2, 3, 4, 5]
*
* // Taking 0 or negative returns empty
* const none = Iterable.take(numbers, 0)
* Array.from(none) // => []
*
* // Useful with infinite iterables
* const naturals = Iterable.range(1)
* const firstFive = Iterable.take(naturals, 5)
* Array.from(firstFive) // => [1, 2, 3, 4, 5]
* ```
*
* @stability stable
* @category getters
* @since 2.0.0
*/
export declare const take: {
/**
* Keeps only a max number of elements from the start of an `Iterable`, creating a new `Iterable`.
*
* **Details**
*
* `n` is rounded down and normalized to a non-negative integer. `NaN` is
* treated as `0`.
*
* **Example** (Taking from the start)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3, 4, 5]
* const firstThree = Iterable.take(numbers, 3)
* Array.from(firstThree) // => [1, 2, 3]
*
* // Taking more than available returns all elements
* const firstTen = Iterable.take(numbers, 10)
* Array.from(firstTen) // => [1, 2, 3, 4, 5]
*
* // Taking 0 or negative returns empty
* const none = Iterable.take(numbers, 0)
* Array.from(none) // => []
*
* // Useful with infinite iterables
* const naturals = Iterable.range(1)
* const firstFive = Iterable.take(naturals, 5)
* Array.from(firstFive) // => [1, 2, 3, 4, 5]
* ```
*
* @stability stable
* @category getters
* @since 2.0.0
*/
(n: number): (self: Iterable) => Iterable;
/**
* Keeps only a max number of elements from the start of an `Iterable`, creating a new `Iterable`.
*
* **Details**
*
* `n` is rounded down and normalized to a non-negative integer. `NaN` is
* treated as `0`.
*
* **Example** (Taking from the start)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3, 4, 5]
* const firstThree = Iterable.take(numbers, 3)
* Array.from(firstThree) // => [1, 2, 3]
*
* // Taking more than available returns all elements
* const firstTen = Iterable.take(numbers, 10)
* Array.from(firstTen) // => [1, 2, 3, 4, 5]
*
* // Taking 0 or negative returns empty
* const none = Iterable.take(numbers, 0)
* Array.from(none) // => []
*
* // Useful with infinite iterables
* const naturals = Iterable.range(1)
* const firstFive = Iterable.take(naturals, 5)
* Array.from(firstFive) // => [1, 2, 3, 4, 5]
* ```
*
* @stability stable
* @category getters
* @since 2.0.0
*/
(self: Iterable, n: number): Iterable;
};
/**
* Takes the longest initial `Iterable` prefix for which all elements satisfy the
* specified predicate.
*
* **Example** (Taking while a predicate holds)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [2, 4, 6, 8, 3, 10, 12]
* const evenPrefix = Iterable.takeWhile(numbers, (x) => x % 2 === 0)
* Array.from(evenPrefix) // => [2, 4, 6, 8]
*
* // With index
* const letters = ["a", "b", "c", "d", "e"]
* const firstThreeByIndex = Iterable.takeWhile(letters, (_, i) => i < 3)
* Array.from(firstThreeByIndex) // => ["a", "b", "c"]
*
* // Stops at first non-matching element
* const mixed = [1, 3, 5, 4, 7, 9]
* const oddPrefix = Iterable.takeWhile(mixed, (x) => x % 2 === 1)
* Array.from(oddPrefix) // => [1, 3, 5]
*
* // Type refinement
* const values: Array = ["a", "b", "c", 1, "d"]
* const stringPrefix = Iterable.takeWhile(
* values,
* (x): x is string => typeof x === "string"
* )
* Array.from(stringPrefix) // => ["a", "b", "c"]
* ```
*
* @stability stable
* @category getters
* @since 2.0.0
*/
export declare const takeWhile: {
/**
* Takes the longest initial `Iterable` prefix for which all elements satisfy the
* specified predicate.
*
* **Example** (Taking while a predicate holds)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [2, 4, 6, 8, 3, 10, 12]
* const evenPrefix = Iterable.takeWhile(numbers, (x) => x % 2 === 0)
* Array.from(evenPrefix) // => [2, 4, 6, 8]
*
* // With index
* const letters = ["a", "b", "c", "d", "e"]
* const firstThreeByIndex = Iterable.takeWhile(letters, (_, i) => i < 3)
* Array.from(firstThreeByIndex) // => ["a", "b", "c"]
*
* // Stops at first non-matching element
* const mixed = [1, 3, 5, 4, 7, 9]
* const oddPrefix = Iterable.takeWhile(mixed, (x) => x % 2 === 1)
* Array.from(oddPrefix) // => [1, 3, 5]
*
* // Type refinement
* const values: Array = ["a", "b", "c", 1, "d"]
* const stringPrefix = Iterable.takeWhile(
* values,
* (x): x is string => typeof x === "string"
* )
* Array.from(stringPrefix) // => ["a", "b", "c"]
* ```
*
* @stability stable
* @category getters
* @since 2.0.0
*/
(refinement: (a: NoInfer, i: number) => a is B): (self: Iterable) => Iterable;
/**
* Takes the longest initial `Iterable` prefix for which all elements satisfy the
* specified predicate.
*
* **Example** (Taking while a predicate holds)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [2, 4, 6, 8, 3, 10, 12]
* const evenPrefix = Iterable.takeWhile(numbers, (x) => x % 2 === 0)
* Array.from(evenPrefix) // => [2, 4, 6, 8]
*
* // With index
* const letters = ["a", "b", "c", "d", "e"]
* const firstThreeByIndex = Iterable.takeWhile(letters, (_, i) => i < 3)
* Array.from(firstThreeByIndex) // => ["a", "b", "c"]
*
* // Stops at first non-matching element
* const mixed = [1, 3, 5, 4, 7, 9]
* const oddPrefix = Iterable.takeWhile(mixed, (x) => x % 2 === 1)
* Array.from(oddPrefix) // => [1, 3, 5]
*
* // Type refinement
* const values: Array = ["a", "b", "c", 1, "d"]
* const stringPrefix = Iterable.takeWhile(
* values,
* (x): x is string => typeof x === "string"
* )
* Array.from(stringPrefix) // => ["a", "b", "c"]
* ```
*
* @stability stable
* @category getters
* @since 2.0.0
*/
(predicate: (a: NoInfer, i: number) => boolean): (self: Iterable) => Iterable;
/**
* Takes the longest initial `Iterable` prefix for which all elements satisfy the
* specified predicate.
*
* **Example** (Taking while a predicate holds)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [2, 4, 6, 8, 3, 10, 12]
* const evenPrefix = Iterable.takeWhile(numbers, (x) => x % 2 === 0)
* Array.from(evenPrefix) // => [2, 4, 6, 8]
*
* // With index
* const letters = ["a", "b", "c", "d", "e"]
* const firstThreeByIndex = Iterable.takeWhile(letters, (_, i) => i < 3)
* Array.from(firstThreeByIndex) // => ["a", "b", "c"]
*
* // Stops at first non-matching element
* const mixed = [1, 3, 5, 4, 7, 9]
* const oddPrefix = Iterable.takeWhile(mixed, (x) => x % 2 === 1)
* Array.from(oddPrefix) // => [1, 3, 5]
*
* // Type refinement
* const values: Array = ["a", "b", "c", 1, "d"]
* const stringPrefix = Iterable.takeWhile(
* values,
* (x): x is string => typeof x === "string"
* )
* Array.from(stringPrefix) // => ["a", "b", "c"]
* ```
*
* @stability stable
* @category getters
* @since 2.0.0
*/
(self: Iterable, refinement: (a: A, i: number) => a is B): Iterable;
/**
* Takes the longest initial `Iterable` prefix for which all elements satisfy the
* specified predicate.
*
* **Example** (Taking while a predicate holds)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [2, 4, 6, 8, 3, 10, 12]
* const evenPrefix = Iterable.takeWhile(numbers, (x) => x % 2 === 0)
* Array.from(evenPrefix) // => [2, 4, 6, 8]
*
* // With index
* const letters = ["a", "b", "c", "d", "e"]
* const firstThreeByIndex = Iterable.takeWhile(letters, (_, i) => i < 3)
* Array.from(firstThreeByIndex) // => ["a", "b", "c"]
*
* // Stops at first non-matching element
* const mixed = [1, 3, 5, 4, 7, 9]
* const oddPrefix = Iterable.takeWhile(mixed, (x) => x % 2 === 1)
* Array.from(oddPrefix) // => [1, 3, 5]
*
* // Type refinement
* const values: Array = ["a", "b", "c", 1, "d"]
* const stringPrefix = Iterable.takeWhile(
* values,
* (x): x is string => typeof x === "string"
* )
* Array.from(stringPrefix) // => ["a", "b", "c"]
* ```
*
* @stability stable
* @category getters
* @since 2.0.0
*/
(self: Iterable, predicate: (a: A, i: number) => boolean): Iterable;
};
/**
* Drops a max number of elements from the start of an `Iterable`
*
* **Details**
*
* `n` is rounded down and normalized to a non-negative integer. `NaN` is
* treated as `0`.
*
* **Example** (Dropping from the start)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3, 4, 5]
* const withoutFirstTwo = Iterable.drop(numbers, 2)
* Array.from(withoutFirstTwo) // => [3, 4, 5]
*
* // Dropping more than available returns empty
* const withoutFirstTen = Iterable.drop(numbers, 10)
* Array.from(withoutFirstTen) // => []
*
* // Dropping 0 or negative returns all elements
* const all = Iterable.drop(numbers, 0)
* Array.from(all) // => [1, 2, 3, 4, 5]
*
* // Combine with take for slicing
* const slice = Iterable.take(Iterable.drop(numbers, 1), 3)
* Array.from(slice) // => [2, 3, 4]
* ```
*
* @stability stable
* @category getters
* @since 2.0.0
*/
export declare const drop: {
/**
* Drops a max number of elements from the start of an `Iterable`
*
* **Details**
*
* `n` is rounded down and normalized to a non-negative integer. `NaN` is
* treated as `0`.
*
* **Example** (Dropping from the start)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3, 4, 5]
* const withoutFirstTwo = Iterable.drop(numbers, 2)
* Array.from(withoutFirstTwo) // => [3, 4, 5]
*
* // Dropping more than available returns empty
* const withoutFirstTen = Iterable.drop(numbers, 10)
* Array.from(withoutFirstTen) // => []
*
* // Dropping 0 or negative returns all elements
* const all = Iterable.drop(numbers, 0)
* Array.from(all) // => [1, 2, 3, 4, 5]
*
* // Combine with take for slicing
* const slice = Iterable.take(Iterable.drop(numbers, 1), 3)
* Array.from(slice) // => [2, 3, 4]
* ```
*
* @stability stable
* @category getters
* @since 2.0.0
*/
(n: number): (self: Iterable) => Iterable;
/**
* Drops a max number of elements from the start of an `Iterable`
*
* **Details**
*
* `n` is rounded down and normalized to a non-negative integer. `NaN` is
* treated as `0`.
*
* **Example** (Dropping from the start)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3, 4, 5]
* const withoutFirstTwo = Iterable.drop(numbers, 2)
* Array.from(withoutFirstTwo) // => [3, 4, 5]
*
* // Dropping more than available returns empty
* const withoutFirstTen = Iterable.drop(numbers, 10)
* Array.from(withoutFirstTen) // => []
*
* // Dropping 0 or negative returns all elements
* const all = Iterable.drop(numbers, 0)
* Array.from(all) // => [1, 2, 3, 4, 5]
*
* // Combine with take for slicing
* const slice = Iterable.take(Iterable.drop(numbers, 1), 3)
* Array.from(slice) // => [2, 3, 4]
* ```
*
* @stability stable
* @category getters
* @since 2.0.0
*/
(self: Iterable, n: number): Iterable;
};
/**
* Returns the first element that satisfies the specified
* predicate, or `None` if no such element exists.
*
* **Example** (Finding the first match)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 3, 4, 6, 8]
* const firstEven = Iterable.findFirst(numbers, (x) => x % 2 === 0)
* firstEven // => Option.some(4)
*
* const firstGreaterThan10 = Iterable.findFirst(numbers, (x) => x > 10)
* firstGreaterThan10 // => Option.none()
*
* // With index
* const letters = ["a", "b", "c", "d"]
* const atEvenIndex = Iterable.findFirst(letters, (_, i) => i % 2 === 0)
* atEvenIndex // => Option.some("a")
*
* // Type refinement
* const mixed: Array = [1, "hello", 2, "world"]
* const firstString = Iterable.findFirst(
* mixed,
* (x): x is string => typeof x === "string"
* )
* firstString // => Option.some("hello")
*
* // Transform during search
* const findSquareRoot = Iterable.findFirst([1, 4, 9, 16], (x) => {
* const sqrt = Math.sqrt(x)
* return Number.isInteger(sqrt) ? Option.some(sqrt) : Option.none()
* })
* findSquareRoot // => Option.some(1)
* ```
*
* @stability stable
* @category searching
* @since 2.0.0
*/
export declare const findFirst: {
/**
* Returns the first element that satisfies the specified
* predicate, or `None` if no such element exists.
*
* **Example** (Finding the first match)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 3, 4, 6, 8]
* const firstEven = Iterable.findFirst(numbers, (x) => x % 2 === 0)
* firstEven // => Option.some(4)
*
* const firstGreaterThan10 = Iterable.findFirst(numbers, (x) => x > 10)
* firstGreaterThan10 // => Option.none()
*
* // With index
* const letters = ["a", "b", "c", "d"]
* const atEvenIndex = Iterable.findFirst(letters, (_, i) => i % 2 === 0)
* atEvenIndex // => Option.some("a")
*
* // Type refinement
* const mixed: Array = [1, "hello", 2, "world"]
* const firstString = Iterable.findFirst(
* mixed,
* (x): x is string => typeof x === "string"
* )
* firstString // => Option.some("hello")
*
* // Transform during search
* const findSquareRoot = Iterable.findFirst([1, 4, 9, 16], (x) => {
* const sqrt = Math.sqrt(x)
* return Number.isInteger(sqrt) ? Option.some(sqrt) : Option.none()
* })
* findSquareRoot // => Option.some(1)
* ```
*
* @stability stable
* @category searching
* @since 2.0.0
*/
(f: (a: NoInfer, i: number) => Option): (self: Iterable) => Option;
/**
* Returns the first element that satisfies the specified
* predicate, or `None` if no such element exists.
*
* **Example** (Finding the first match)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 3, 4, 6, 8]
* const firstEven = Iterable.findFirst(numbers, (x) => x % 2 === 0)
* firstEven // => Option.some(4)
*
* const firstGreaterThan10 = Iterable.findFirst(numbers, (x) => x > 10)
* firstGreaterThan10 // => Option.none()
*
* // With index
* const letters = ["a", "b", "c", "d"]
* const atEvenIndex = Iterable.findFirst(letters, (_, i) => i % 2 === 0)
* atEvenIndex // => Option.some("a")
*
* // Type refinement
* const mixed: Array = [1, "hello", 2, "world"]
* const firstString = Iterable.findFirst(
* mixed,
* (x): x is string => typeof x === "string"
* )
* firstString // => Option.some("hello")
*
* // Transform during search
* const findSquareRoot = Iterable.findFirst([1, 4, 9, 16], (x) => {
* const sqrt = Math.sqrt(x)
* return Number.isInteger(sqrt) ? Option.some(sqrt) : Option.none()
* })
* findSquareRoot // => Option.some(1)
* ```
*
* @stability stable
* @category searching
* @since 2.0.0
*/
(refinement: (a: NoInfer, i: number) => a is B): (self: Iterable) => Option;
/**
* Returns the first element that satisfies the specified
* predicate, or `None` if no such element exists.
*
* **Example** (Finding the first match)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 3, 4, 6, 8]
* const firstEven = Iterable.findFirst(numbers, (x) => x % 2 === 0)
* firstEven // => Option.some(4)
*
* const firstGreaterThan10 = Iterable.findFirst(numbers, (x) => x > 10)
* firstGreaterThan10 // => Option.none()
*
* // With index
* const letters = ["a", "b", "c", "d"]
* const atEvenIndex = Iterable.findFirst(letters, (_, i) => i % 2 === 0)
* atEvenIndex // => Option.some("a")
*
* // Type refinement
* const mixed: Array = [1, "hello", 2, "world"]
* const firstString = Iterable.findFirst(
* mixed,
* (x): x is string => typeof x === "string"
* )
* firstString // => Option.some("hello")
*
* // Transform during search
* const findSquareRoot = Iterable.findFirst([1, 4, 9, 16], (x) => {
* const sqrt = Math.sqrt(x)
* return Number.isInteger(sqrt) ? Option.some(sqrt) : Option.none()
* })
* findSquareRoot // => Option.some(1)
* ```
*
* @stability stable
* @category searching
* @since 2.0.0
*/
(predicate: (a: NoInfer, i: number) => boolean): (self: Iterable) => Option;
/**
* Returns the first element that satisfies the specified
* predicate, or `None` if no such element exists.
*
* **Example** (Finding the first match)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 3, 4, 6, 8]
* const firstEven = Iterable.findFirst(numbers, (x) => x % 2 === 0)
* firstEven // => Option.some(4)
*
* const firstGreaterThan10 = Iterable.findFirst(numbers, (x) => x > 10)
* firstGreaterThan10 // => Option.none()
*
* // With index
* const letters = ["a", "b", "c", "d"]
* const atEvenIndex = Iterable.findFirst(letters, (_, i) => i % 2 === 0)
* atEvenIndex // => Option.some("a")
*
* // Type refinement
* const mixed: Array = [1, "hello", 2, "world"]
* const firstString = Iterable.findFirst(
* mixed,
* (x): x is string => typeof x === "string"
* )
* firstString // => Option.some("hello")
*
* // Transform during search
* const findSquareRoot = Iterable.findFirst([1, 4, 9, 16], (x) => {
* const sqrt = Math.sqrt(x)
* return Number.isInteger(sqrt) ? Option.some(sqrt) : Option.none()
* })
* findSquareRoot // => Option.some(1)
* ```
*
* @stability stable
* @category searching
* @since 2.0.0
*/
(self: Iterable, f: (a: A, i: number) => Option): Option;
/**
* Returns the first element that satisfies the specified
* predicate, or `None` if no such element exists.
*
* **Example** (Finding the first match)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 3, 4, 6, 8]
* const firstEven = Iterable.findFirst(numbers, (x) => x % 2 === 0)
* firstEven // => Option.some(4)
*
* const firstGreaterThan10 = Iterable.findFirst(numbers, (x) => x > 10)
* firstGreaterThan10 // => Option.none()
*
* // With index
* const letters = ["a", "b", "c", "d"]
* const atEvenIndex = Iterable.findFirst(letters, (_, i) => i % 2 === 0)
* atEvenIndex // => Option.some("a")
*
* // Type refinement
* const mixed: Array = [1, "hello", 2, "world"]
* const firstString = Iterable.findFirst(
* mixed,
* (x): x is string => typeof x === "string"
* )
* firstString // => Option.some("hello")
*
* // Transform during search
* const findSquareRoot = Iterable.findFirst([1, 4, 9, 16], (x) => {
* const sqrt = Math.sqrt(x)
* return Number.isInteger(sqrt) ? Option.some(sqrt) : Option.none()
* })
* findSquareRoot // => Option.some(1)
* ```
*
* @stability stable
* @category searching
* @since 2.0.0
*/
(self: Iterable, refinement: (a: A, i: number) => a is B): Option;
/**
* Returns the first element that satisfies the specified
* predicate, or `None` if no such element exists.
*
* **Example** (Finding the first match)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 3, 4, 6, 8]
* const firstEven = Iterable.findFirst(numbers, (x) => x % 2 === 0)
* firstEven // => Option.some(4)
*
* const firstGreaterThan10 = Iterable.findFirst(numbers, (x) => x > 10)
* firstGreaterThan10 // => Option.none()
*
* // With index
* const letters = ["a", "b", "c", "d"]
* const atEvenIndex = Iterable.findFirst(letters, (_, i) => i % 2 === 0)
* atEvenIndex // => Option.some("a")
*
* // Type refinement
* const mixed: Array = [1, "hello", 2, "world"]
* const firstString = Iterable.findFirst(
* mixed,
* (x): x is string => typeof x === "string"
* )
* firstString // => Option.some("hello")
*
* // Transform during search
* const findSquareRoot = Iterable.findFirst([1, 4, 9, 16], (x) => {
* const sqrt = Math.sqrt(x)
* return Number.isInteger(sqrt) ? Option.some(sqrt) : Option.none()
* })
* findSquareRoot // => Option.some(1)
* ```
*
* @stability stable
* @category searching
* @since 2.0.0
*/
(self: Iterable, predicate: (a: A, i: number) => boolean): Option;
};
/**
* Finds the last element for which a predicate holds.
*
* **Example** (Finding the last match)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 3, 4, 6, 8, 2]
* const lastEven = Iterable.findLast(numbers, (x) => x % 2 === 0)
* lastEven // => Option.some(2)
*
* const lastGreaterThan10 = Iterable.findLast(numbers, (x) => x > 10)
* lastGreaterThan10 // => Option.none()
*
* // With index
* const letters = ["a", "b", "c", "d", "e"]
* const lastAtEvenIndex = Iterable.findLast(letters, (_, i) => i % 2 === 0)
* lastAtEvenIndex // => Option.some("e")
*
* // Type refinement
* const mixed: Array = [1, "hello", 2, "world", 3]
* const lastString = Iterable.findLast(
* mixed,
* (x): x is string => typeof x === "string"
* )
* lastString // => Option.some("world")
* ```
*
* @stability stable
* @category searching
* @since 2.0.0
*/
export declare const findLast: {
/**
* Finds the last element for which a predicate holds.
*
* **Example** (Finding the last match)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 3, 4, 6, 8, 2]
* const lastEven = Iterable.findLast(numbers, (x) => x % 2 === 0)
* lastEven // => Option.some(2)
*
* const lastGreaterThan10 = Iterable.findLast(numbers, (x) => x > 10)
* lastGreaterThan10 // => Option.none()
*
* // With index
* const letters = ["a", "b", "c", "d", "e"]
* const lastAtEvenIndex = Iterable.findLast(letters, (_, i) => i % 2 === 0)
* lastAtEvenIndex // => Option.some("e")
*
* // Type refinement
* const mixed: Array = [1, "hello", 2, "world", 3]
* const lastString = Iterable.findLast(
* mixed,
* (x): x is string => typeof x === "string"
* )
* lastString // => Option.some("world")
* ```
*
* @stability stable
* @category searching
* @since 2.0.0
*/
(f: (a: NoInfer, i: number) => Option): (self: Iterable) => Option;
/**
* Finds the last element for which a predicate holds.
*
* **Example** (Finding the last match)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 3, 4, 6, 8, 2]
* const lastEven = Iterable.findLast(numbers, (x) => x % 2 === 0)
* lastEven // => Option.some(2)
*
* const lastGreaterThan10 = Iterable.findLast(numbers, (x) => x > 10)
* lastGreaterThan10 // => Option.none()
*
* // With index
* const letters = ["a", "b", "c", "d", "e"]
* const lastAtEvenIndex = Iterable.findLast(letters, (_, i) => i % 2 === 0)
* lastAtEvenIndex // => Option.some("e")
*
* // Type refinement
* const mixed: Array = [1, "hello", 2, "world", 3]
* const lastString = Iterable.findLast(
* mixed,
* (x): x is string => typeof x === "string"
* )
* lastString // => Option.some("world")
* ```
*
* @stability stable
* @category searching
* @since 2.0.0
*/
(refinement: (a: NoInfer, i: number) => a is B): (self: Iterable) => Option;
/**
* Finds the last element for which a predicate holds.
*
* **Example** (Finding the last match)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 3, 4, 6, 8, 2]
* const lastEven = Iterable.findLast(numbers, (x) => x % 2 === 0)
* lastEven // => Option.some(2)
*
* const lastGreaterThan10 = Iterable.findLast(numbers, (x) => x > 10)
* lastGreaterThan10 // => Option.none()
*
* // With index
* const letters = ["a", "b", "c", "d", "e"]
* const lastAtEvenIndex = Iterable.findLast(letters, (_, i) => i % 2 === 0)
* lastAtEvenIndex // => Option.some("e")
*
* // Type refinement
* const mixed: Array = [1, "hello", 2, "world", 3]
* const lastString = Iterable.findLast(
* mixed,
* (x): x is string => typeof x === "string"
* )
* lastString // => Option.some("world")
* ```
*
* @stability stable
* @category searching
* @since 2.0.0
*/
(predicate: (a: NoInfer, i: number) => boolean): (self: Iterable) => Option;
/**
* Finds the last element for which a predicate holds.
*
* **Example** (Finding the last match)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 3, 4, 6, 8, 2]
* const lastEven = Iterable.findLast(numbers, (x) => x % 2 === 0)
* lastEven // => Option.some(2)
*
* const lastGreaterThan10 = Iterable.findLast(numbers, (x) => x > 10)
* lastGreaterThan10 // => Option.none()
*
* // With index
* const letters = ["a", "b", "c", "d", "e"]
* const lastAtEvenIndex = Iterable.findLast(letters, (_, i) => i % 2 === 0)
* lastAtEvenIndex // => Option.some("e")
*
* // Type refinement
* const mixed: Array = [1, "hello", 2, "world", 3]
* const lastString = Iterable.findLast(
* mixed,
* (x): x is string => typeof x === "string"
* )
* lastString // => Option.some("world")
* ```
*
* @stability stable
* @category searching
* @since 2.0.0
*/
(self: Iterable, f: (a: A, i: number) => Option): Option;
/**
* Finds the last element for which a predicate holds.
*
* **Example** (Finding the last match)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 3, 4, 6, 8, 2]
* const lastEven = Iterable.findLast(numbers, (x) => x % 2 === 0)
* lastEven // => Option.some(2)
*
* const lastGreaterThan10 = Iterable.findLast(numbers, (x) => x > 10)
* lastGreaterThan10 // => Option.none()
*
* // With index
* const letters = ["a", "b", "c", "d", "e"]
* const lastAtEvenIndex = Iterable.findLast(letters, (_, i) => i % 2 === 0)
* lastAtEvenIndex // => Option.some("e")
*
* // Type refinement
* const mixed: Array = [1, "hello", 2, "world", 3]
* const lastString = Iterable.findLast(
* mixed,
* (x): x is string => typeof x === "string"
* )
* lastString // => Option.some("world")
* ```
*
* @stability stable
* @category searching
* @since 2.0.0
*/
(self: Iterable, refinement: (a: A, i: number) => a is B): Option;
/**
* Finds the last element for which a predicate holds.
*
* **Example** (Finding the last match)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* const numbers = [1, 3, 4, 6, 8, 2]
* const lastEven = Iterable.findLast(numbers, (x) => x % 2 === 0)
* lastEven // => Option.some(2)
*
* const lastGreaterThan10 = Iterable.findLast(numbers, (x) => x > 10)
* lastGreaterThan10 // => Option.none()
*
* // With index
* const letters = ["a", "b", "c", "d", "e"]
* const lastAtEvenIndex = Iterable.findLast(letters, (_, i) => i % 2 === 0)
* lastAtEvenIndex // => Option.some("e")
*
* // Type refinement
* const mixed: Array = [1, "hello", 2, "world", 3]
* const lastString = Iterable.findLast(
* mixed,
* (x): x is string => typeof x === "string"
* )
* lastString // => Option.some("world")
* ```
*
* @stability stable
* @category searching
* @since 2.0.0
*/
(self: Iterable, predicate: (a: A, i: number) => boolean): Option;
};
/**
* Takes two `Iterable`s and returns an `Iterable` of corresponding pairs.
*
* **Example** (Zipping iterables)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3]
* const letters = ["a", "b", "c"]
* const zipped = Iterable.zip(numbers, letters)
* Array.from(zipped) // => [[1, "a"], [2, "b"], [3, "c"]]
*
* // Different lengths - shorter one determines result length
* const short = [1, 2]
* const long = ["a", "b", "c", "d"]
* const partial = Iterable.zip(short, long)
* Array.from(partial) // => [[1, "a"], [2, "b"]]
*
* // Works with any iterables
* const range = Iterable.range(1, 3)
* const word = "abc"
* const mixed = Iterable.zip(range, word)
* Array.from(mixed) // => [[1, "a"], [2, "b"], [3, "c"]]
*
* // Create indexed pairs
* const values = ["apple", "banana", "cherry"]
* const indices = Iterable.range(0, 2)
* const indexed = Iterable.zip(indices, values)
* Array.from(indexed) // => [[0, "apple"], [1, "banana"], [2, "cherry"]]
* ```
*
* @stability stable
* @category zipping
* @since 2.0.0
*/
export declare const zip: {
/**
* Takes two `Iterable`s and returns an `Iterable` of corresponding pairs.
*
* **Example** (Zipping iterables)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3]
* const letters = ["a", "b", "c"]
* const zipped = Iterable.zip(numbers, letters)
* Array.from(zipped) // => [[1, "a"], [2, "b"], [3, "c"]]
*
* // Different lengths - shorter one determines result length
* const short = [1, 2]
* const long = ["a", "b", "c", "d"]
* const partial = Iterable.zip(short, long)
* Array.from(partial) // => [[1, "a"], [2, "b"]]
*
* // Works with any iterables
* const range = Iterable.range(1, 3)
* const word = "abc"
* const mixed = Iterable.zip(range, word)
* Array.from(mixed) // => [[1, "a"], [2, "b"], [3, "c"]]
*
* // Create indexed pairs
* const values = ["apple", "banana", "cherry"]
* const indices = Iterable.range(0, 2)
* const indexed = Iterable.zip(indices, values)
* Array.from(indexed) // => [[0, "apple"], [1, "banana"], [2, "cherry"]]
* ```
*
* @stability stable
* @category zipping
* @since 2.0.0
*/
(that: Iterable): (self: Iterable) => Iterable<[A, B]>;
/**
* Takes two `Iterable`s and returns an `Iterable` of corresponding pairs.
*
* **Example** (Zipping iterables)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3]
* const letters = ["a", "b", "c"]
* const zipped = Iterable.zip(numbers, letters)
* Array.from(zipped) // => [[1, "a"], [2, "b"], [3, "c"]]
*
* // Different lengths - shorter one determines result length
* const short = [1, 2]
* const long = ["a", "b", "c", "d"]
* const partial = Iterable.zip(short, long)
* Array.from(partial) // => [[1, "a"], [2, "b"]]
*
* // Works with any iterables
* const range = Iterable.range(1, 3)
* const word = "abc"
* const mixed = Iterable.zip(range, word)
* Array.from(mixed) // => [[1, "a"], [2, "b"], [3, "c"]]
*
* // Create indexed pairs
* const values = ["apple", "banana", "cherry"]
* const indices = Iterable.range(0, 2)
* const indexed = Iterable.zip(indices, values)
* Array.from(indexed) // => [[0, "apple"], [1, "banana"], [2, "cherry"]]
* ```
*
* @stability stable
* @category zipping
* @since 2.0.0
*/
(self: Iterable, that: Iterable): Iterable<[A, B]>;
};
/**
* Applies a function to pairs of elements at the same index in two `Iterable`s, collecting the results. If one
* input `Iterable` is short, excess elements of the longer `Iterable` are discarded.
*
* **Example** (Zipping with a combining function)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Add corresponding elements
* const a = [1, 2, 3, 4]
* const b = [10, 20, 30, 40]
* const sums = Iterable.zipWith(a, b, (x, y) => x + y)
* Array.from(sums) // => [11, 22, 33, 44]
*
* // Combine strings
* const firstNames = ["John", "Jane", "Bob"]
* const lastNames = ["Doe", "Smith", "Johnson"]
* const fullNames = Iterable.zipWith(
* firstNames,
* lastNames,
* (first, last) => `${first} ${last}`
* )
* Array.from(fullNames) // => ["John Doe", "Jane Smith", "Bob Johnson"]
*
* // Different lengths - stops at shorter
* const short = [1, 2]
* const long = ["a", "b", "c", "d"]
* const combined = Iterable.zipWith(
* short,
* long,
* (num, letter) => `${num}${letter}`
* )
* Array.from(combined) // => ["1a", "2b"]
*
* // Complex transformations
* const prices = [10.99, 25.50, 5.00]
* const quantities = [2, 1, 3]
* const totals = Iterable.zipWith(prices, quantities, (price, qty) => {
* return Math.round(price * qty * 100) / 100 // round to 2 decimal places
* })
* Array.from(totals) // => [21.98, 25.5, 15]
* ```
*
* @stability stable
* @category zipping
* @since 2.0.0
*/
export declare const zipWith: {
/**
* Applies a function to pairs of elements at the same index in two `Iterable`s, collecting the results. If one
* input `Iterable` is short, excess elements of the longer `Iterable` are discarded.
*
* **Example** (Zipping with a combining function)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Add corresponding elements
* const a = [1, 2, 3, 4]
* const b = [10, 20, 30, 40]
* const sums = Iterable.zipWith(a, b, (x, y) => x + y)
* Array.from(sums) // => [11, 22, 33, 44]
*
* // Combine strings
* const firstNames = ["John", "Jane", "Bob"]
* const lastNames = ["Doe", "Smith", "Johnson"]
* const fullNames = Iterable.zipWith(
* firstNames,
* lastNames,
* (first, last) => `${first} ${last}`
* )
* Array.from(fullNames) // => ["John Doe", "Jane Smith", "Bob Johnson"]
*
* // Different lengths - stops at shorter
* const short = [1, 2]
* const long = ["a", "b", "c", "d"]
* const combined = Iterable.zipWith(
* short,
* long,
* (num, letter) => `${num}${letter}`
* )
* Array.from(combined) // => ["1a", "2b"]
*
* // Complex transformations
* const prices = [10.99, 25.50, 5.00]
* const quantities = [2, 1, 3]
* const totals = Iterable.zipWith(prices, quantities, (price, qty) => {
* return Math.round(price * qty * 100) / 100 // round to 2 decimal places
* })
* Array.from(totals) // => [21.98, 25.5, 15]
* ```
*
* @stability stable
* @category zipping
* @since 2.0.0
*/
(that: Iterable, f: (a: A, b: B) => C): (self: Iterable) => Iterable;
/**
* Applies a function to pairs of elements at the same index in two `Iterable`s, collecting the results. If one
* input `Iterable` is short, excess elements of the longer `Iterable` are discarded.
*
* **Example** (Zipping with a combining function)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Add corresponding elements
* const a = [1, 2, 3, 4]
* const b = [10, 20, 30, 40]
* const sums = Iterable.zipWith(a, b, (x, y) => x + y)
* Array.from(sums) // => [11, 22, 33, 44]
*
* // Combine strings
* const firstNames = ["John", "Jane", "Bob"]
* const lastNames = ["Doe", "Smith", "Johnson"]
* const fullNames = Iterable.zipWith(
* firstNames,
* lastNames,
* (first, last) => `${first} ${last}`
* )
* Array.from(fullNames) // => ["John Doe", "Jane Smith", "Bob Johnson"]
*
* // Different lengths - stops at shorter
* const short = [1, 2]
* const long = ["a", "b", "c", "d"]
* const combined = Iterable.zipWith(
* short,
* long,
* (num, letter) => `${num}${letter}`
* )
* Array.from(combined) // => ["1a", "2b"]
*
* // Complex transformations
* const prices = [10.99, 25.50, 5.00]
* const quantities = [2, 1, 3]
* const totals = Iterable.zipWith(prices, quantities, (price, qty) => {
* return Math.round(price * qty * 100) / 100 // round to 2 decimal places
* })
* Array.from(totals) // => [21.98, 25.5, 15]
* ```
*
* @stability stable
* @category zipping
* @since 2.0.0
*/
(self: Iterable, that: Iterable, f: (a: A, b: B) => C): Iterable;
};
/**
* Places a separator between members of an `Iterable`.
*
* **When to use**
*
* Use to lazily insert a separator between adjacent values.
*
* **Details**
*
* If the input is a non-empty array, the result is also a non-empty array.
*
* **Example** (Interspersing separators)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Join numbers with separator
* const numbers = [1, 2, 3, 4]
* const withCommas = Iterable.intersperse(numbers, ",")
* Array.from(withCommas) // => [1, ",", 2, ",", 3, ",", 4]
*
* // Join words with spaces
* const words = ["hello", "world", "from", "effect"]
* const sentence = Iterable.intersperse(words, " ")
* Array.from(sentence).join("") // => "hello world from effect"
*
* // Empty iterable remains empty
* const empty = Iterable.empty()
* const stillEmpty = Iterable.intersperse(empty, "-")
* Array.from(stillEmpty) // => []
*
* // Single element has no separators added
* const single = [42]
* const noSeparator = Iterable.intersperse(single, "|")
* Array.from(noSeparator) // => [42]
*
* // Build CSS-like strings
* const styles = ["color: red", "font-size: 14px", "margin: 10px"]
* const css = Iterable.intersperse(styles, "; ")
* Array.from(css).join("") // => "color: red; font-size: 14px; margin: 10px"
* ```
*
* @stability stable
* @category combining
* @since 2.0.0
*/
export declare const intersperse: {
/**
* Places a separator between members of an `Iterable`.
*
* **When to use**
*
* Use to lazily insert a separator between adjacent values.
*
* **Details**
*
* If the input is a non-empty array, the result is also a non-empty array.
*
* **Example** (Interspersing separators)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Join numbers with separator
* const numbers = [1, 2, 3, 4]
* const withCommas = Iterable.intersperse(numbers, ",")
* Array.from(withCommas) // => [1, ",", 2, ",", 3, ",", 4]
*
* // Join words with spaces
* const words = ["hello", "world", "from", "effect"]
* const sentence = Iterable.intersperse(words, " ")
* Array.from(sentence).join("") // => "hello world from effect"
*
* // Empty iterable remains empty
* const empty = Iterable.empty()
* const stillEmpty = Iterable.intersperse(empty, "-")
* Array.from(stillEmpty) // => []
*
* // Single element has no separators added
* const single = [42]
* const noSeparator = Iterable.intersperse(single, "|")
* Array.from(noSeparator) // => [42]
*
* // Build CSS-like strings
* const styles = ["color: red", "font-size: 14px", "margin: 10px"]
* const css = Iterable.intersperse(styles, "; ")
* Array.from(css).join("") // => "color: red; font-size: 14px; margin: 10px"
* ```
*
* @stability stable
* @category combining
* @since 2.0.0
*/
(middle: B): (self: Iterable) => Iterable;
/**
* Places a separator between members of an `Iterable`.
*
* **When to use**
*
* Use to lazily insert a separator between adjacent values.
*
* **Details**
*
* If the input is a non-empty array, the result is also a non-empty array.
*
* **Example** (Interspersing separators)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Join numbers with separator
* const numbers = [1, 2, 3, 4]
* const withCommas = Iterable.intersperse(numbers, ",")
* Array.from(withCommas) // => [1, ",", 2, ",", 3, ",", 4]
*
* // Join words with spaces
* const words = ["hello", "world", "from", "effect"]
* const sentence = Iterable.intersperse(words, " ")
* Array.from(sentence).join("") // => "hello world from effect"
*
* // Empty iterable remains empty
* const empty = Iterable.empty()
* const stillEmpty = Iterable.intersperse(empty, "-")
* Array.from(stillEmpty) // => []
*
* // Single element has no separators added
* const single = [42]
* const noSeparator = Iterable.intersperse(single, "|")
* Array.from(noSeparator) // => [42]
*
* // Build CSS-like strings
* const styles = ["color: red", "font-size: 14px", "margin: 10px"]
* const css = Iterable.intersperse(styles, "; ")
* Array.from(css).join("") // => "color: red; font-size: 14px; margin: 10px"
* ```
*
* @stability stable
* @category combining
* @since 2.0.0
*/
(self: Iterable, middle: B): Iterable;
};
/**
* Returns a function that checks if an `Iterable` contains a given value using a provided `isEquivalent` function.
*
* **Example** (Checking membership with custom equivalence)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Custom equivalence for objects
* const byId = (a: { id: number }, b: { id: number }) => a.id === b.id
* const containsById = Iterable.containsWith(byId)
*
* const users = [{ id: 1 }, { id: 2 }]
* const hasUser1 = containsById(users, { id: 1 })
* hasUser1 // => true
*
* // Case-insensitive string comparison
* const caseInsensitive = (a: string, b: string) =>
* a.toLowerCase() === b.toLowerCase()
* const containsCaseInsensitive = Iterable.containsWith(caseInsensitive)
*
* const words = ["Hello", "World"]
* const hasHello = containsCaseInsensitive(words, "hello")
* hasHello // => true
*
* // Approximate number comparison
* const approxEqual = (a: number, b: number) => Math.abs(a - b) < 0.1
* const containsApprox = Iterable.containsWith(approxEqual)
*
* const values = [1.0, 2.0, 3.0]
* const hasAlmostTwo = containsApprox(values, 2.05)
* hasAlmostTwo // => true
* ```
*
* @stability stable
* @category predicates
* @since 2.0.0
*/
export declare const containsWith: (isEquivalent: (self: A, that: A) => boolean) => {
(a: A): (self: Iterable) => boolean;
(self: Iterable, a: A): boolean;
};
/**
* Checks whether an iterable contains a value using Effect's default `Equal`
* equivalence.
*
* **Details**
*
* Can be called as `contains(self, value)` or curried as
* `contains(value)(self)`.
*
* **Example** (Checking membership)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3, 4, 5]
* Iterable.contains(numbers, 3) // => true
* Iterable.contains(numbers, 6) // => false
*
* const letters = "hello"
* Iterable.contains(letters, "l") // => true
* Iterable.contains(letters, "x") // => false
*
* // Works with any iterable
* const range = Iterable.range(1, 100)
* Iterable.contains(range, 50) // => true
* Iterable.contains(range, 150) // => false
*
* // Curried version
* const containsThree = Iterable.contains(3)
* containsThree([1, 2, 3]) // => true
* containsThree([4, 5, 6]) // => false
* ```
*
* @stability stable
* @category predicates
* @since 2.0.0
*/
export declare const contains: {
/**
* Checks whether an iterable contains a value using Effect's default `Equal`
* equivalence.
*
* **Details**
*
* Can be called as `contains(self, value)` or curried as
* `contains(value)(self)`.
*
* **Example** (Checking membership)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3, 4, 5]
* Iterable.contains(numbers, 3) // => true
* Iterable.contains(numbers, 6) // => false
*
* const letters = "hello"
* Iterable.contains(letters, "l") // => true
* Iterable.contains(letters, "x") // => false
*
* // Works with any iterable
* const range = Iterable.range(1, 100)
* Iterable.contains(range, 50) // => true
* Iterable.contains(range, 150) // => false
*
* // Curried version
* const containsThree = Iterable.contains(3)
* containsThree([1, 2, 3]) // => true
* containsThree([4, 5, 6]) // => false
* ```
*
* @stability stable
* @category predicates
* @since 2.0.0
*/
(a: A): (self: Iterable) => boolean;
/**
* Checks whether an iterable contains a value using Effect's default `Equal`
* equivalence.
*
* **Details**
*
* Can be called as `contains(self, value)` or curried as
* `contains(value)(self)`.
*
* **Example** (Checking membership)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3, 4, 5]
* Iterable.contains(numbers, 3) // => true
* Iterable.contains(numbers, 6) // => false
*
* const letters = "hello"
* Iterable.contains(letters, "l") // => true
* Iterable.contains(letters, "x") // => false
*
* // Works with any iterable
* const range = Iterable.range(1, 100)
* Iterable.contains(range, 50) // => true
* Iterable.contains(range, 150) // => false
*
* // Curried version
* const containsThree = Iterable.contains(3)
* containsThree([1, 2, 3]) // => true
* containsThree([4, 5, 6]) // => false
* ```
*
* @stability stable
* @category predicates
* @since 2.0.0
*/
(self: Iterable, a: A): boolean;
};
/**
* Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
* the `Iterable`.
* `n` is rounded down and normalized to at least `1`; `NaN` and non-positive
* values therefore produce singleton pieces.
*
* **Example** (Chunking an iterable)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
* const chunks = Iterable.chunksOf(numbers, 3)
* Array.from(chunks) // => [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
*
* // Last chunk can be shorter
* const uneven = [1, 2, 3, 4, 5, 6, 7]
* const chunks2 = Iterable.chunksOf(uneven, 3)
* Array.from(chunks2) // => [[1, 2, 3], [4, 5, 6], [7]]
*
* // Chunk size larger than iterable
* const small = [1, 2]
* const chunks3 = Iterable.chunksOf(small, 5)
* Array.from(chunks3) // => [[1, 2]]
*
* // Process data in batches
* const data = Iterable.range(1, 100)
* const batches = Iterable.chunksOf(data, 10)
* const batchSums = Iterable.map(
* batches,
* (batch) => Iterable.reduce(batch, 0, (sum, n) => sum + n)
* )
* Array.from(Iterable.take(batchSums, 3)) // => [55, 155, 255]
* ```
*
* @stability stable
* @category splitting
* @since 2.0.0
*/
export declare const chunksOf: {
/**
* Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
* the `Iterable`.
* `n` is rounded down and normalized to at least `1`; `NaN` and non-positive
* values therefore produce singleton pieces.
*
* **Example** (Chunking an iterable)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
* const chunks = Iterable.chunksOf(numbers, 3)
* Array.from(chunks) // => [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
*
* // Last chunk can be shorter
* const uneven = [1, 2, 3, 4, 5, 6, 7]
* const chunks2 = Iterable.chunksOf(uneven, 3)
* Array.from(chunks2) // => [[1, 2, 3], [4, 5, 6], [7]]
*
* // Chunk size larger than iterable
* const small = [1, 2]
* const chunks3 = Iterable.chunksOf(small, 5)
* Array.from(chunks3) // => [[1, 2]]
*
* // Process data in batches
* const data = Iterable.range(1, 100)
* const batches = Iterable.chunksOf(data, 10)
* const batchSums = Iterable.map(
* batches,
* (batch) => Iterable.reduce(batch, 0, (sum, n) => sum + n)
* )
* Array.from(Iterable.take(batchSums, 3)) // => [55, 155, 255]
* ```
*
* @stability stable
* @category splitting
* @since 2.0.0
*/
(n: number): (self: Iterable) => Iterable>;
/**
* Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
* the `Iterable`.
* `n` is rounded down and normalized to at least `1`; `NaN` and non-positive
* values therefore produce singleton pieces.
*
* **Example** (Chunking an iterable)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
* const chunks = Iterable.chunksOf(numbers, 3)
* Array.from(chunks) // => [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
*
* // Last chunk can be shorter
* const uneven = [1, 2, 3, 4, 5, 6, 7]
* const chunks2 = Iterable.chunksOf(uneven, 3)
* Array.from(chunks2) // => [[1, 2, 3], [4, 5, 6], [7]]
*
* // Chunk size larger than iterable
* const small = [1, 2]
* const chunks3 = Iterable.chunksOf(small, 5)
* Array.from(chunks3) // => [[1, 2]]
*
* // Process data in batches
* const data = Iterable.range(1, 100)
* const batches = Iterable.chunksOf(data, 10)
* const batchSums = Iterable.map(
* batches,
* (batch) => Iterable.reduce(batch, 0, (sum, n) => sum + n)
* )
* Array.from(Iterable.take(batchSums, 3)) // => [55, 155, 255]
* ```
*
* @stability stable
* @category splitting
* @since 2.0.0
*/
(self: Iterable, n: number): Iterable>;
};
/**
* Groups equal, consecutive elements of an `Iterable` into `NonEmptyArray`s using the provided `isEquivalent` function.
*
* **Example** (Grouping consecutive elements with custom equivalence)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Group consecutive equal numbers
* const numbers = [1, 1, 2, 2, 2, 3, 1, 1]
* const grouped = Iterable.groupWith(numbers, (a, b) => a === b)
* Array.from(grouped) // => [[1, 1], [2, 2, 2], [3], [1, 1]]
*
* // Case-insensitive grouping of strings
* const words = ["Apple", "APPLE", "banana", "Banana", "cherry"]
* const caseInsensitive = (a: string, b: string) =>
* a.toLowerCase() === b.toLowerCase()
* const groupedWords = Iterable.groupWith(words, caseInsensitive)
* Array.from(groupedWords) // => [["Apple", "APPLE"], ["banana", "Banana"], ["cherry"]]
*
* // Group by approximate equality
* const floats = [1.1, 1.12, 1.9, 2.01, 2.05, 3.5]
* const approxEqual = (a: number, b: number) => Math.abs(a - b) < 0.2
* const groupedFloats = Iterable.groupWith(floats, approxEqual)
* Array.from(groupedFloats) // => [[1.1, 1.12], [1.9, 2.01, 2.05], [3.5]]
*
* // Only groups consecutive elements
* const scattered = [1, 2, 1, 2, 1]
* const scatteredGroups = Iterable.groupWith(scattered, (a, b) => a === b)
* Array.from(scatteredGroups) // => [[1], [2], [1], [2], [1]]
* ```
*
* @stability stable
* @category grouping
* @since 2.0.0
*/
export declare const groupWith: {
/**
* Groups equal, consecutive elements of an `Iterable` into `NonEmptyArray`s using the provided `isEquivalent` function.
*
* **Example** (Grouping consecutive elements with custom equivalence)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Group consecutive equal numbers
* const numbers = [1, 1, 2, 2, 2, 3, 1, 1]
* const grouped = Iterable.groupWith(numbers, (a, b) => a === b)
* Array.from(grouped) // => [[1, 1], [2, 2, 2], [3], [1, 1]]
*
* // Case-insensitive grouping of strings
* const words = ["Apple", "APPLE", "banana", "Banana", "cherry"]
* const caseInsensitive = (a: string, b: string) =>
* a.toLowerCase() === b.toLowerCase()
* const groupedWords = Iterable.groupWith(words, caseInsensitive)
* Array.from(groupedWords) // => [["Apple", "APPLE"], ["banana", "Banana"], ["cherry"]]
*
* // Group by approximate equality
* const floats = [1.1, 1.12, 1.9, 2.01, 2.05, 3.5]
* const approxEqual = (a: number, b: number) => Math.abs(a - b) < 0.2
* const groupedFloats = Iterable.groupWith(floats, approxEqual)
* Array.from(groupedFloats) // => [[1.1, 1.12], [1.9, 2.01, 2.05], [3.5]]
*
* // Only groups consecutive elements
* const scattered = [1, 2, 1, 2, 1]
* const scatteredGroups = Iterable.groupWith(scattered, (a, b) => a === b)
* Array.from(scatteredGroups) // => [[1], [2], [1], [2], [1]]
* ```
*
* @stability stable
* @category grouping
* @since 2.0.0
*/
(isEquivalent: (self: A, that: A) => boolean): (self: Iterable) => Iterable>;
/**
* Groups equal, consecutive elements of an `Iterable` into `NonEmptyArray`s using the provided `isEquivalent` function.
*
* **Example** (Grouping consecutive elements with custom equivalence)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Group consecutive equal numbers
* const numbers = [1, 1, 2, 2, 2, 3, 1, 1]
* const grouped = Iterable.groupWith(numbers, (a, b) => a === b)
* Array.from(grouped) // => [[1, 1], [2, 2, 2], [3], [1, 1]]
*
* // Case-insensitive grouping of strings
* const words = ["Apple", "APPLE", "banana", "Banana", "cherry"]
* const caseInsensitive = (a: string, b: string) =>
* a.toLowerCase() === b.toLowerCase()
* const groupedWords = Iterable.groupWith(words, caseInsensitive)
* Array.from(groupedWords) // => [["Apple", "APPLE"], ["banana", "Banana"], ["cherry"]]
*
* // Group by approximate equality
* const floats = [1.1, 1.12, 1.9, 2.01, 2.05, 3.5]
* const approxEqual = (a: number, b: number) => Math.abs(a - b) < 0.2
* const groupedFloats = Iterable.groupWith(floats, approxEqual)
* Array.from(groupedFloats) // => [[1.1, 1.12], [1.9, 2.01, 2.05], [3.5]]
*
* // Only groups consecutive elements
* const scattered = [1, 2, 1, 2, 1]
* const scatteredGroups = Iterable.groupWith(scattered, (a, b) => a === b)
* Array.from(scatteredGroups) // => [[1], [2], [1], [2], [1]]
* ```
*
* @stability stable
* @category grouping
* @since 2.0.0
*/
(self: Iterable, isEquivalent: (self: A, that: A) => boolean): Iterable>;
};
/**
* Groups equal, consecutive elements of an `Iterable` into `NonEmptyArray`s.
*
* **Example** (Grouping consecutive elements)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const numbers = [1, 1, 2, 2, 2, 3, 1, 1]
* const grouped = Iterable.group(numbers)
* Array.from(grouped) // => [[1, 1], [2, 2, 2], [3], [1, 1]]
*
* const letters = "aabbccaa"
* const groupedLetters = Iterable.group(letters)
* Array.from(groupedLetters) // => [["a", "a"], ["b", "b"], ["c", "c"], ["a", "a"]]
*
* // Works with objects using deep equality
* const objects = [
* { type: "A", value: 1 },
* { type: "A", value: 1 },
* { type: "B", value: 2 },
* { type: "A", value: 1 }
* ]
* const groupedObjects = Iterable.group(objects)
* Array.from(groupedObjects).length // => 3
* // Note: Only consecutive equal objects are grouped together
* ```
*
* @stability stable
* @category grouping
* @since 2.0.0
*/
export declare const group: (self: Iterable) => Iterable>;
/**
* Groups all elements by the string or symbol key returned by `f`.
*
* **Details**
*
* Each property in the returned record contains a non-empty array of elements
* that produced that key. Unlike `group`, matching elements do not need to be
* consecutive.
*
* **Gotchas**
*
* When the key function returns a finite union of string literals or unique
* symbols, the result preserves those keys as optional properties because the
* input may not produce every key. Open `string` and `symbol` key types retain
* their record index signatures.
*
* **Example** (Grouping by a key)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Group by string length
* const words = ["a", "bb", "ccc", "dd", "eee", "f"]
* const byLength = Iterable.groupBy(words, (word) => word.length.toString())
* byLength // => { "1": ["a", "f"], "2": ["bb", "dd"], "3": ["ccc", "eee"] }
*
* // Group by first letter
* const names = ["Alice", "Bob", "Charlie", "David", "Anna", "Betty"]
* const byFirstLetter = Iterable.groupBy(names, (name) => name[0])
* byFirstLetter // => { A: ["Alice", "Anna"], B: ["Bob", "Betty"], C: ["Charlie"], D: ["David"] }
*
* // Group by category
* const items = [
* { name: "apple", category: "fruit" },
* { name: "carrot", category: "vegetable" },
* { name: "banana", category: "fruit" },
* { name: "broccoli", category: "vegetable" }
* ]
* const byCategory = Iterable.groupBy(items, (item) => item.category)
* Object.keys(byCategory) // => ["fruit", "vegetable"]
*
* // Group numbers by even/odd
* const numbers = [1, 2, 3, 4, 5, 6]
* const evenOdd = Iterable.groupBy(numbers, (n) => n % 2 === 0 ? "even" : "odd")
* evenOdd // => { odd: [1, 3, 5], even: [2, 4, 6] }
* ```
*
* @stability stable
* @category grouping
* @since 2.0.0
*/
export declare const groupBy: {
/**
* Groups all elements by the string or symbol key returned by `f`.
*
* **Details**
*
* Each property in the returned record contains a non-empty array of elements
* that produced that key. Unlike `group`, matching elements do not need to be
* consecutive.
*
* **Gotchas**
*
* When the key function returns a finite union of string literals or unique
* symbols, the result preserves those keys as optional properties because the
* input may not produce every key. Open `string` and `symbol` key types retain
* their record index signatures.
*
* **Example** (Grouping by a key)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Group by string length
* const words = ["a", "bb", "ccc", "dd", "eee", "f"]
* const byLength = Iterable.groupBy(words, (word) => word.length.toString())
* byLength // => { "1": ["a", "f"], "2": ["bb", "dd"], "3": ["ccc", "eee"] }
*
* // Group by first letter
* const names = ["Alice", "Bob", "Charlie", "David", "Anna", "Betty"]
* const byFirstLetter = Iterable.groupBy(names, (name) => name[0])
* byFirstLetter // => { A: ["Alice", "Anna"], B: ["Bob", "Betty"], C: ["Charlie"], D: ["David"] }
*
* // Group by category
* const items = [
* { name: "apple", category: "fruit" },
* { name: "carrot", category: "vegetable" },
* { name: "banana", category: "fruit" },
* { name: "broccoli", category: "vegetable" }
* ]
* const byCategory = Iterable.groupBy(items, (item) => item.category)
* Object.keys(byCategory) // => ["fruit", "vegetable"]
*
* // Group numbers by even/odd
* const numbers = [1, 2, 3, 4, 5, 6]
* const evenOdd = Iterable.groupBy(numbers, (n) => n % 2 === 0 ? "even" : "odd")
* evenOdd // => { odd: [1, 3, 5], even: [2, 4, 6] }
* ```
*
* @stability stable
* @category grouping
* @since 2.0.0
*/
(f: (a: A) => K): (self: Iterable) => Record.ReadonlyRecord.GroupByResult>;
/**
* Groups all elements by the string or symbol key returned by `f`.
*
* **Details**
*
* Each property in the returned record contains a non-empty array of elements
* that produced that key. Unlike `group`, matching elements do not need to be
* consecutive.
*
* **Gotchas**
*
* When the key function returns a finite union of string literals or unique
* symbols, the result preserves those keys as optional properties because the
* input may not produce every key. Open `string` and `symbol` key types retain
* their record index signatures.
*
* **Example** (Grouping by a key)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Group by string length
* const words = ["a", "bb", "ccc", "dd", "eee", "f"]
* const byLength = Iterable.groupBy(words, (word) => word.length.toString())
* byLength // => { "1": ["a", "f"], "2": ["bb", "dd"], "3": ["ccc", "eee"] }
*
* // Group by first letter
* const names = ["Alice", "Bob", "Charlie", "David", "Anna", "Betty"]
* const byFirstLetter = Iterable.groupBy(names, (name) => name[0])
* byFirstLetter // => { A: ["Alice", "Anna"], B: ["Bob", "Betty"], C: ["Charlie"], D: ["David"] }
*
* // Group by category
* const items = [
* { name: "apple", category: "fruit" },
* { name: "carrot", category: "vegetable" },
* { name: "banana", category: "fruit" },
* { name: "broccoli", category: "vegetable" }
* ]
* const byCategory = Iterable.groupBy(items, (item) => item.category)
* Object.keys(byCategory) // => ["fruit", "vegetable"]
*
* // Group numbers by even/odd
* const numbers = [1, 2, 3, 4, 5, 6]
* const evenOdd = Iterable.groupBy(numbers, (n) => n % 2 === 0 ? "even" : "odd")
* evenOdd // => { odd: [1, 3, 5], even: [2, 4, 6] }
* ```
*
* @stability stable
* @category grouping
* @since 2.0.0
*/
(self: Iterable, f: (a: A) => K): Record.ReadonlyRecord.GroupByResult>;
};
/**
* Creates an empty iterable that yields no elements.
*
* **When to use**
*
* Use when you need an empty iterable as a typed "no data" value or a base
* case for iterable operations.
*
* **Example** (Creating an empty iterable)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* Array.from(Iterable.empty()) // => []
* ```
*
* @stability stable
* @category constructors
* @since 2.0.0
*/
export declare const empty: () => Iterable;
/**
* Creates an iterable containing a single element.
*
* **When to use**
*
* Use to wrap a single value in an iterable context so it can be combined
* with other iterable operations.
*
* **Example** (Wrapping a single value)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* const single = Iterable.of(42)
* Array.from(single) // => [42]
*
* // Useful for creating homogeneous sequences
* const sequences = [
* Iterable.of("hello"),
* Iterable.range(1, 3),
* Iterable.empty()
* ]
*
* // Can be used with flatMap for conditional inclusion
* const numbers = [1, 2, 3, 4, 5]
* const evensOnly = Iterable.flatMap(
* numbers,
* (n) => n % 2 === 0 ? Iterable.of(n) : Iterable.empty()
* )
* Array.from(evensOnly) // => [2, 4]
* ```
*
* @stability stable
* @category constructors
* @since 2.0.0
*/
export declare const of: (a: A) => Iterable;
/**
* Transforms each element of an iterable using a function.
*
* **Details**
*
* This is one of the most fundamental operations for working with iterables.
* It applies a transformation function to each element, creating a new iterable
* with the transformed values. The operation is lazy, so elements are only
* transformed when the iterable is consumed.
*
* **Example** (Mapping elements)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Transform numbers to their squares
* const numbers = [1, 2, 3, 4, 5]
* const squares = Iterable.map(numbers, (x) => x * x)
* Array.from(squares) // => [1, 4, 9, 16, 25]
*
* // Use index in transformation
* const indexed = Iterable.map(["a", "b", "c"], (char, i) => `${i}: ${char}`)
* Array.from(indexed) // => ["0: a", "1: b", "2: c"]
*
* Array.from(Iterable.map(
* Iterable.map([1, 2, 3], (x) => x * 2),
* (x) => x + 1
* )) // => [3, 5, 7]
* ```
*
* @stability stable
* @category mapping
* @since 2.0.0
*/
export declare const map: {
/**
* Transforms each element of an iterable using a function.
*
* **Details**
*
* This is one of the most fundamental operations for working with iterables.
* It applies a transformation function to each element, creating a new iterable
* with the transformed values. The operation is lazy, so elements are only
* transformed when the iterable is consumed.
*
* **Example** (Mapping elements)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Transform numbers to their squares
* const numbers = [1, 2, 3, 4, 5]
* const squares = Iterable.map(numbers, (x) => x * x)
* Array.from(squares) // => [1, 4, 9, 16, 25]
*
* // Use index in transformation
* const indexed = Iterable.map(["a", "b", "c"], (char, i) => `${i}: ${char}`)
* Array.from(indexed) // => ["0: a", "1: b", "2: c"]
*
* Array.from(Iterable.map(
* Iterable.map([1, 2, 3], (x) => x * 2),
* (x) => x + 1
* )) // => [3, 5, 7]
* ```
*
* @stability stable
* @category mapping
* @since 2.0.0
*/
(f: (a: NoInfer, i: number) => B): (self: Iterable) => Iterable;
/**
* Transforms each element of an iterable using a function.
*
* **Details**
*
* This is one of the most fundamental operations for working with iterables.
* It applies a transformation function to each element, creating a new iterable
* with the transformed values. The operation is lazy, so elements are only
* transformed when the iterable is consumed.
*
* **Example** (Mapping elements)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Transform numbers to their squares
* const numbers = [1, 2, 3, 4, 5]
* const squares = Iterable.map(numbers, (x) => x * x)
* Array.from(squares) // => [1, 4, 9, 16, 25]
*
* // Use index in transformation
* const indexed = Iterable.map(["a", "b", "c"], (char, i) => `${i}: ${char}`)
* Array.from(indexed) // => ["0: a", "1: b", "2: c"]
*
* Array.from(Iterable.map(
* Iterable.map([1, 2, 3], (x) => x * 2),
* (x) => x + 1
* )) // => [3, 5, 7]
* ```
*
* @stability stable
* @category mapping
* @since 2.0.0
*/
(self: Iterable, f: (a: NoInfer, i: number) => B): Iterable;
};
/**
* Applies a function to each element in an Iterable and returns a new Iterable containing the concatenated mapped elements.
*
* **Example** (Flat mapping iterables)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Expand each number to a range
* const numbers = [1, 2, 3]
* const expanded = Iterable.flatMap(numbers, (n) => Iterable.range(1, n))
* Array.from(expanded) // => [1, 1, 2, 1, 2, 3]
*
* // Split strings into characters
* const words = ["hi", "bye"]
* const chars = Iterable.flatMap(words, (word) => word)
* Array.from(chars) // => ["h", "i", "b", "y", "e"]
*
* // Conditional expansion with empty iterables
* const values = [1, 2, 3, 4, 5]
* const evenMultiples = Iterable.flatMap(
* values,
* (n) => n % 2 === 0 ? [n, n * 2, n * 3] : []
* )
* Array.from(evenMultiples) // => [2, 4, 6, 4, 8, 12]
*
* // Use index in transformation
* const letters = ["a", "b", "c"]
* const indexed = Iterable.flatMap(
* letters,
* (letter, i) => Iterable.replicate(letter, i + 1)
* )
* Array.from(indexed) // => ["a", "b", "b", "c", "c", "c"]
* ```
*
* @stability stable
* @category sequencing
* @since 2.0.0
*/
export declare const flatMap: {
/**
* Applies a function to each element in an Iterable and returns a new Iterable containing the concatenated mapped elements.
*
* **Example** (Flat mapping iterables)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Expand each number to a range
* const numbers = [1, 2, 3]
* const expanded = Iterable.flatMap(numbers, (n) => Iterable.range(1, n))
* Array.from(expanded) // => [1, 1, 2, 1, 2, 3]
*
* // Split strings into characters
* const words = ["hi", "bye"]
* const chars = Iterable.flatMap(words, (word) => word)
* Array.from(chars) // => ["h", "i", "b", "y", "e"]
*
* // Conditional expansion with empty iterables
* const values = [1, 2, 3, 4, 5]
* const evenMultiples = Iterable.flatMap(
* values,
* (n) => n % 2 === 0 ? [n, n * 2, n * 3] : []
* )
* Array.from(evenMultiples) // => [2, 4, 6, 4, 8, 12]
*
* // Use index in transformation
* const letters = ["a", "b", "c"]
* const indexed = Iterable.flatMap(
* letters,
* (letter, i) => Iterable.replicate(letter, i + 1)
* )
* Array.from(indexed) // => ["a", "b", "b", "c", "c", "c"]
* ```
*
* @stability stable
* @category sequencing
* @since 2.0.0
*/
(f: (a: NoInfer, i: number) => Iterable): (self: Iterable) => Iterable;
/**
* Applies a function to each element in an Iterable and returns a new Iterable containing the concatenated mapped elements.
*
* **Example** (Flat mapping iterables)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Expand each number to a range
* const numbers = [1, 2, 3]
* const expanded = Iterable.flatMap(numbers, (n) => Iterable.range(1, n))
* Array.from(expanded) // => [1, 1, 2, 1, 2, 3]
*
* // Split strings into characters
* const words = ["hi", "bye"]
* const chars = Iterable.flatMap(words, (word) => word)
* Array.from(chars) // => ["h", "i", "b", "y", "e"]
*
* // Conditional expansion with empty iterables
* const values = [1, 2, 3, 4, 5]
* const evenMultiples = Iterable.flatMap(
* values,
* (n) => n % 2 === 0 ? [n, n * 2, n * 3] : []
* )
* Array.from(evenMultiples) // => [2, 4, 6, 4, 8, 12]
*
* // Use index in transformation
* const letters = ["a", "b", "c"]
* const indexed = Iterable.flatMap(
* letters,
* (letter, i) => Iterable.replicate(letter, i + 1)
* )
* Array.from(indexed) // => ["a", "b", "b", "c", "c", "c"]
* ```
*
* @stability stable
* @category sequencing
* @since 2.0.0
*/
(self: Iterable, f: (a: NoInfer, i: number) => Iterable): Iterable;
};
/**
* Flattens an Iterable of Iterables into a single Iterable
*
* **Example** (Flattening nested iterables)
*
* ```ts import.meta.vitest
* import { Iterable } from "effect"
*
* // Flatten nested arrays
* const nested = [[1, 2], [3, 4], [5, 6]]
* const flat = Iterable.flatten(nested)
* Array.from(flat) // => [1, 2, 3, 4, 5, 6]
*
* // Flatten different iterable types
* const mixed: Array> = ["ab", "cd"]
* const flatMixed = Iterable.flatten(mixed)
* Array.from(flatMixed) // => ["a", "b", "c", "d"]
*
* // Flatten deeply nested (only one level)
* const deepNested = [[[1, 2]], [[3, 4]]]
* const oneLevelFlat = Iterable.flatten(deepNested)
* Array.from(oneLevelFlat) // => [[1, 2], [3, 4]]
* // [[1, 2], [3, 4]] (still contains arrays)
*
* // Empty iterables are handled correctly
* const withEmpty = [[1, 2], [], [3, 4], []]
* const flatWithEmpty = Iterable.flatten(withEmpty)
* Array.from(flatWithEmpty) // => [1, 2, 3, 4]
* ```
*
* @stability stable
* @category sequencing
* @since 2.0.0
*/
export declare const flatten: (self: Iterable>) => Iterable;
/**
* Transforms elements of an iterable using a function that returns a `Result`, keeping only successful values.
*
* **Details**
*
* This combines mapping and filtering in a single operation. The function is
* applied to each element, and only elements that result in `Result.succeed`
* are included in the result.
*
* **Example** (Filtering and transforming Result values)
*
* ```ts import.meta.vitest
* import { Iterable, Result } from "effect"
*
* // Parse strings to numbers, keeping only valid ones
* const strings = ["1", "2", "invalid", "4", "not-a-number"]
* const numbers = Iterable.filterMap(strings, (s) => {
* const num = parseInt(s)
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
* })
* Array.from(numbers) // => [1, 2, 4]
*
* // Extract specific properties from objects
* const users = [
* { name: "Alice", age: 25, email: "alice@example.com" },
* { name: "Bob", age: 17, email: undefined },
* { name: "Charlie", age: 30, email: "charlie@example.com" },
* { name: "David", age: 16, email: undefined }
* ]
* const adultEmails = Iterable.filterMap(
* users,
* (user) =>
* user.age >= 18 && user.email ? Result.succeed(user.email) : Result.failVoid
* )
* Array.from(adultEmails) // => ["alice@example.com", "charlie@example.com"]
*
* // Use index in transformation
* const items = ["a", "b", "c", "d", "e"]
* const evenIndexItems = Iterable.filterMap(
* items,
* (item, i) => i % 2 === 0 ? Result.succeed(`${i}: ${item}`) : Result.failVoid
* )
* Array.from(evenIndexItems) // => ["0: a", "2: c", "4: e"]
* ```
*
* @stability stable
* @category filtering
* @since 2.0.0
*/
export declare const filterMap: {
/**
* Transforms elements of an iterable using a function that returns a `Result`, keeping only successful values.
*
* **Details**
*
* This combines mapping and filtering in a single operation. The function is
* applied to each element, and only elements that result in `Result.succeed`
* are included in the result.
*
* **Example** (Filtering and transforming Result values)
*
* ```ts import.meta.vitest
* import { Iterable, Result } from "effect"
*
* // Parse strings to numbers, keeping only valid ones
* const strings = ["1", "2", "invalid", "4", "not-a-number"]
* const numbers = Iterable.filterMap(strings, (s) => {
* const num = parseInt(s)
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
* })
* Array.from(numbers) // => [1, 2, 4]
*
* // Extract specific properties from objects
* const users = [
* { name: "Alice", age: 25, email: "alice@example.com" },
* { name: "Bob", age: 17, email: undefined },
* { name: "Charlie", age: 30, email: "charlie@example.com" },
* { name: "David", age: 16, email: undefined }
* ]
* const adultEmails = Iterable.filterMap(
* users,
* (user) =>
* user.age >= 18 && user.email ? Result.succeed(user.email) : Result.failVoid
* )
* Array.from(adultEmails) // => ["alice@example.com", "charlie@example.com"]
*
* // Use index in transformation
* const items = ["a", "b", "c", "d", "e"]
* const evenIndexItems = Iterable.filterMap(
* items,
* (item, i) => i % 2 === 0 ? Result.succeed(`${i}: ${item}`) : Result.failVoid
* )
* Array.from(evenIndexItems) // => ["0: a", "2: c", "4: e"]
* ```
*
* @stability stable
* @category filtering
* @since 2.0.0
*/
(f: (input: A, i: number) => Result): (self: Iterable) => Iterable;
/**
* Transforms elements of an iterable using a function that returns a `Result`, keeping only successful values.
*
* **Details**
*
* This combines mapping and filtering in a single operation. The function is
* applied to each element, and only elements that result in `Result.succeed`
* are included in the result.
*
* **Example** (Filtering and transforming Result values)
*
* ```ts import.meta.vitest
* import { Iterable, Result } from "effect"
*
* // Parse strings to numbers, keeping only valid ones
* const strings = ["1", "2", "invalid", "4", "not-a-number"]
* const numbers = Iterable.filterMap(strings, (s) => {
* const num = parseInt(s)
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
* })
* Array.from(numbers) // => [1, 2, 4]
*
* // Extract specific properties from objects
* const users = [
* { name: "Alice", age: 25, email: "alice@example.com" },
* { name: "Bob", age: 17, email: undefined },
* { name: "Charlie", age: 30, email: "charlie@example.com" },
* { name: "David", age: 16, email: undefined }
* ]
* const adultEmails = Iterable.filterMap(
* users,
* (user) =>
* user.age >= 18 && user.email ? Result.succeed(user.email) : Result.failVoid
* )
* Array.from(adultEmails) // => ["alice@example.com", "charlie@example.com"]
*
* // Use index in transformation
* const items = ["a", "b", "c", "d", "e"]
* const evenIndexItems = Iterable.filterMap(
* items,
* (item, i) => i % 2 === 0 ? Result.succeed(`${i}: ${item}`) : Result.failVoid
* )
* Array.from(evenIndexItems) // => ["0: a", "2: c", "4: e"]
* ```
*
* @stability stable
* @category filtering
* @since 2.0.0
*/
(self: Iterable, f: (input: A, i: number) => Result): Iterable;
};
/**
* Transforms all elements of the `Iterable` for as long as the specified function succeeds.
*
* **Example** (Filtering and transforming until failure)
*
* ```ts import.meta.vitest
* import { Iterable, Result } from "effect"
*
* // Parse numbers until we hit an invalid one
* const strings = ["1", "2", "3", "invalid", "4", "5"]
* const numbers = Iterable.filterMapWhile(strings, (s) => {
* const num = parseInt(s)
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
* })
* Array.from(numbers) // => [1, 2, 3]
*
* // Take elements while they meet a condition and transform them
* const values = [2, 4, 6, 7, 8, 10]
* const doubledEvens = Iterable.filterMapWhile(
* values,
* (n) => n % 2 === 0 ? Result.succeed(n * 2) : Result.failVoid
* )
* Array.from(doubledEvens) // => [4, 8, 12]
*
* // Process with index until condition fails
* const letters = ["a", "b", "c", "d", "e"]
* const indexedUntilC = Iterable.filterMapWhile(
* letters,
* (letter, i) => letter !== "c" ? Result.succeed(`${i}: ${letter}`) : Result.failVoid
* )
* Array.from(indexedUntilC) // => ["0: a", "1: b"]
* ```
*
* @stability stable
* @category filtering
* @since 2.0.0
*/
export declare const filterMapWhile: {
/**
* Transforms all elements of the `Iterable` for as long as the specified function succeeds.
*
* **Example** (Filtering and transforming until failure)
*
* ```ts import.meta.vitest
* import { Iterable, Result } from "effect"
*
* // Parse numbers until we hit an invalid one
* const strings = ["1", "2", "3", "invalid", "4", "5"]
* const numbers = Iterable.filterMapWhile(strings, (s) => {
* const num = parseInt(s)
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
* })
* Array.from(numbers) // => [1, 2, 3]
*
* // Take elements while they meet a condition and transform them
* const values = [2, 4, 6, 7, 8, 10]
* const doubledEvens = Iterable.filterMapWhile(
* values,
* (n) => n % 2 === 0 ? Result.succeed(n * 2) : Result.failVoid
* )
* Array.from(doubledEvens) // => [4, 8, 12]
*
* // Process with index until condition fails
* const letters = ["a", "b", "c", "d", "e"]
* const indexedUntilC = Iterable.filterMapWhile(
* letters,
* (letter, i) => letter !== "c" ? Result.succeed(`${i}: ${letter}`) : Result.failVoid
* )
* Array.from(indexedUntilC) // => ["0: a", "1: b"]
* ```
*
* @stability stable
* @category filtering
* @since 2.0.0
*/
(f: (input: A, i: number) => Result): (self: Iterable) => Iterable;
/**
* Transforms all elements of the `Iterable` for as long as the specified function succeeds.
*
* **Example** (Filtering and transforming until failure)
*
* ```ts import.meta.vitest
* import { Iterable, Result } from "effect"
*
* // Parse numbers until we hit an invalid one
* const strings = ["1", "2", "3", "invalid", "4", "5"]
* const numbers = Iterable.filterMapWhile(strings, (s) => {
* const num = parseInt(s)
* return isNaN(num) ? Result.failVoid : Result.succeed(num)
* })
* Array.from(numbers) // => [1, 2, 3]
*
* // Take elements while they meet a condition and transform them
* const values = [2, 4, 6, 7, 8, 10]
* const doubledEvens = Iterable.filterMapWhile(
* values,
* (n) => n % 2 === 0 ? Result.succeed(n * 2) : Result.failVoid
* )
* Array.from(doubledEvens) // => [4, 8, 12]
*
* // Process with index until condition fails
* const letters = ["a", "b", "c", "d", "e"]
* const indexedUntilC = Iterable.filterMapWhile(
* letters,
* (letter, i) => letter !== "c" ? Result.succeed(`${i}: ${letter}`) : Result.failVoid
* )
* Array.from(indexedUntilC) // => ["0: a", "1: b"]
* ```
*
* @stability stable
* @category filtering
* @since 2.0.0
*/
(self: Iterable, f: (input: A, i: number) => Result): Iterable;
};
/**
* Retrieves the `Some` values from an `Iterable` of `Option`s.
*
* **Example** (Extracting Some values)
*
* ```ts import.meta.vitest
* import { Iterable, Option } from "effect"
*
* Array.from(Iterable.getSomes([Option.some(1), Option.none(), Option.some(2)])) // => [1, 2]
* ```
*
* @stability stable
* @category filtering
* @since 2.0.0
*/
export declare const getSomes: (self: Iterable