import * as Equivalence from "./Equivalence.ts"; import type { LazyArg } from "./Function.ts"; import type { TypeLambda } from "./HKT.ts"; import * as Option from "./Option.ts"; import * as Order from "./Order.ts"; import type * as Predicate from "./Predicate.ts"; import * as Record from "./Record.ts"; import * as Reducer from "./Reducer.ts"; import * as Result from "./Result.ts"; import type { NoInfer, TupleOf } from "./Types.ts"; /** * Exposes the global array constructor. * * **When to use** * * Use to access native JavaScript array constructor methods such as `isArray` * or `from` from the Effect module namespace. * * **Example** (Accessing the Array constructor) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.Array === globalThis.Array // => true * ``` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Array: ArrayConstructor; /** * Type lambda for `ReadonlyArray`, used for higher-kinded type operations. * * @stability stable * @category utility types * @since 2.0.0 */ export interface ReadonlyArrayTypeLambda extends TypeLambda { readonly type: ReadonlyArray; } /** * A readonly array guaranteed to have at least one element. * * **When to use** * * Use when non-emptiness must be tracked at the type level while preventing mutation. * Many Array module functions accept or return this type. * * **Example** (Typing a non-empty array) * * ```ts import.meta.vitest * import type { Array } from "effect" * * const nonEmpty: Array.NonEmptyReadonlyArray = [1, 2, 3] * const head: number = nonEmpty[0] // guaranteed to exist * * head // => 1 * ``` * * @see {@link NonEmptyArray} — mutable counterpart * @see {@link isReadonlyArrayNonEmpty} — narrow a `ReadonlyArray` to this type * * @stability stable * @category models * @since 2.0.0 */ export type NonEmptyReadonlyArray = readonly [A, ...Array]; /** * A mutable array guaranteed to have at least one element. * * **When to use** * * Use when mutation is acceptable and non-emptiness must be tracked at the type * level. * * **Details** * * This is the mutable counterpart of {@link NonEmptyReadonlyArray}. Most Array * module functions return `NonEmptyArray` when the result is guaranteed * non-empty. * * **Example** (Typing a mutable non-empty array) * * ```ts import.meta.vitest * import type { Array } from "effect" * * const nonEmpty: Array.NonEmptyArray = [1, 2, 3] * nonEmpty.push(4) * * nonEmpty // => [1, 2, 3, 4] * ``` * * @see {@link NonEmptyReadonlyArray} — readonly counterpart * @see {@link isArrayNonEmpty} — narrow an `Array` to this type * * @stability stable * @category models * @since 2.0.0 */ export type NonEmptyArray = [A, ...Array]; /** * Creates a `NonEmptyArray` from one or more elements. * * **When to use** * * Use when you need to create a typed non-empty array from literal values. * * **Details** * * The element type is inferred as the union of all arguments. Because at least * one argument is required, this always returns a `NonEmptyArray`. * * **Example** (Creating an array from values) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.make(1, 2, 3) // => [1, 2, 3] * ``` * * @see {@link of} — create a single-element array * @see {@link fromIterable} — create from any iterable * * @stability stable * @category constructors * @since 2.0.0 */ export declare const make: >(...elements: Elements) => NonEmptyArray; /** * Creates a new `Array` of the specified length with all slots uninitialized. * * **When to use** * * Use when you need a pre-sized array that will be filled imperatively. * * **Details** * * `n` is rounded down. `NaN` and non-positive values are treated as `0`. * Elements are typed as `A | undefined` because the slots are empty. * * **Example** (Allocating a fixed-size array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.allocate(3).length // => 3 * ``` * * @see {@link makeBy} — create an array by computing each element * * @stability stable * @category constructors * @since 2.0.0 */ export declare const allocate: (n: number) => Array; /** * Creates a `NonEmptyArray` of length `n` where element `i` is computed by `f(i)`. * * **When to use** * * Use when you need to compute each array element from its index. * * **Details** * * `n` is rounded down and normalized to an integer greater than or equal to 1. * `NaN` is treated as `1`, so this function always returns at least one * element. Supports both data-first and data-last usage. * * **Example** (Generating values from indices) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.makeBy(5, (n) => n * 2) // => [0, 2, 4, 6, 8] * ``` * * @see {@link range} — create a range of integers * @see {@link replicate} — repeat a single value * * @stability stable * @category constructors * @since 2.0.0 */ export declare const makeBy: { /** * Creates a `NonEmptyArray` of length `n` where element `i` is computed by `f(i)`. * * **When to use** * * Use when you need to compute each array element from its index. * * **Details** * * `n` is rounded down and normalized to an integer greater than or equal to 1. * `NaN` is treated as `1`, so this function always returns at least one * element. Supports both data-first and data-last usage. * * **Example** (Generating values from indices) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.makeBy(5, (n) => n * 2) // => [0, 2, 4, 6, 8] * ``` * * @see {@link range} — create a range of integers * @see {@link replicate} — repeat a single value * * @stability stable * @category constructors * @since 2.0.0 */ (f: (i: number) => A): (n: number) => NonEmptyArray; /** * Creates a `NonEmptyArray` of length `n` where element `i` is computed by `f(i)`. * * **When to use** * * Use when you need to compute each array element from its index. * * **Details** * * `n` is rounded down and normalized to an integer greater than or equal to 1. * `NaN` is treated as `1`, so this function always returns at least one * element. Supports both data-first and data-last usage. * * **Example** (Generating values from indices) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.makeBy(5, (n) => n * 2) // => [0, 2, 4, 6, 8] * ``` * * @see {@link range} — create a range of integers * @see {@link replicate} — repeat a single value * * @stability stable * @category constructors * @since 2.0.0 */ (n: number, f: (i: number) => A): NonEmptyArray; }; /** * Creates a `NonEmptyArray` containing a range of integers, inclusive on both * ends. * * **When to use** * * Use when you need a non-empty sequence of consecutive integers. * * **Details** * * If `start > end`, returns `[start]`. * * **Example** (Creating a range) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.range(1, 3) // => [1, 2, 3] * ``` * * @see {@link makeBy} — generate values from a function * * @stability stable * @category constructors * @since 2.0.0 */ export declare const range: (start: number, end: number) => NonEmptyArray; /** * Creates a `NonEmptyArray` containing a value repeated `n` times. * * **When to use** * * Use when you need a non-empty array containing repeated copies of one value. * * **Details** * * `n` is normalized to an integer greater than or equal to 1, so this function * always returns at least one element. Supports both data-first and data-last * usage. * * **Example** (Repeating a value) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.replicate("a", 3) // => ["a", "a", "a"] * ``` * * @see {@link makeBy} — vary values based on index * * @stability stable * @category constructors * @since 2.0.0 */ export declare const replicate: { /** * Creates a `NonEmptyArray` containing a value repeated `n` times. * * **When to use** * * Use when you need a non-empty array containing repeated copies of one value. * * **Details** * * `n` is normalized to an integer greater than or equal to 1, so this function * always returns at least one element. Supports both data-first and data-last * usage. * * **Example** (Repeating a value) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.replicate("a", 3) // => ["a", "a", "a"] * ``` * * @see {@link makeBy} — vary values based on index * * @stability stable * @category constructors * @since 2.0.0 */ (n: number): (a: A) => NonEmptyArray; /** * Creates a `NonEmptyArray` containing a value repeated `n` times. * * **When to use** * * Use when you need a non-empty array containing repeated copies of one value. * * **Details** * * `n` is normalized to an integer greater than or equal to 1, so this function * always returns at least one element. Supports both data-first and data-last * usage. * * **Example** (Repeating a value) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.replicate("a", 3) // => ["a", "a", "a"] * ``` * * @see {@link makeBy} — vary values based on index * * @stability stable * @category constructors * @since 2.0.0 */ (a: A, n: number): NonEmptyArray; }; /** * Converts an `Iterable` to an `Array`. * * **When to use** * * Use to convert any `Iterable` (Set, Generator, etc.) into an array. * * **Details** * * If the input is already an array, this returns it by reference without * copying. Otherwise, it creates a new array from the iterable. Use `copy` if * you need a fresh array even when the input is already an array. * * **Example** (Converting a Set to an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.fromIterable(new Set([1, 2, 3])) // => [1, 2, 3] * ``` * * @see {@link ensure} — wrap a single value or return an existing array * @see {@link copy} — create a shallow copy of an array * * @stability stable * @category constructors * @since 2.0.0 */ export declare const fromIterable: (collection: Iterable) => Array; /** * Normalizes a value that is either a single element or an array into an array. * * **When to use** * * Use to normalize input that may be a single value or an array into a consistent * array. * * **Details** * * If the input is already an array, this returns it by reference. If the input * is a single value, this wraps it in a one-element array. This is useful for * APIs that accept `A | Array`. * * **Example** (Normalizing input) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.ensure("a") // => ["a"] * Array.ensure(["a", "b", "c"]) // => ["a", "b", "c"] * ``` * * @see {@link of} — always wrap in a single-element array * @see {@link fromIterable} — convert any iterable * * @stability stable * @category constructors * @since 3.3.0 */ export declare const ensure: (self: ReadonlyArray | A) => Array; /** * Converts a record into an array of `[key, value]` tuples. * * **When to use** * * Use to convert a record into an array of key-value tuples for iteration or * transformation. * * **Details** * * Key order follows `Object.entries` semantics. Empty records produce an empty * array. * * **Example** (Converting a record to entries) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.fromRecord({ a: 1, b: 2, c: 3 }) // => [["a", 1], ["b", 2], ["c", 3]] * ``` * * @see {@link Record.toEntries} the equivalent function from the Record module * @see {@link Record.fromEntries} to build a record from an array of tuples * * @stability stable * @category converting * @since 2.0.0 */ export declare const fromRecord: (self: Readonly>) => Array<[K, A]>; /** * Converts an `Option` to an array: `Some(a)` becomes `[a]`, `None` becomes `[]`. * * **When to use** * * Use to convert a single `Option` into an array for downstream array operations. * * **Example** (Converting an Option to an array) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.fromOption(Option.some(1)) // => [1] * Array.fromOption(Option.none()) // => [] * ``` * * @see {@link getSomes} — extract `Some` values from an array of Options * * @stability stable * @category converting * @since 2.0.0 */ export declare const fromOption: (self: Option.Option) => Array; /** * Pattern-matches on an array, handling empty and non-empty cases separately. * * **When to use** * * Use when you need to branch on whether an array is empty. * * **Details** * * `onNonEmpty` receives a `NonEmptyArray` for mutable arrays and a * `NonEmptyReadonlyArray` otherwise. Data-last calls default to the readonly * callback, so the returned function still accepts `ReadonlyArray`. Supports * both data-first and data-last usage. * * **Example** (Branching on emptiness) * * ```ts import.meta.vitest * import { Array } from "effect" * * const describe = Array.match({ * onEmpty: () => "empty", * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}` * }) * * describe([]) // => "empty" * describe([1, 2, 3]) // => "head: 1, tail: 2" * ``` * * @see {@link matchLeft} — destructures into head + tail * @see {@link matchRight} — destructures into init + last * * @stability stable * @category pattern matching * @since 2.0.0 */ export declare const match: { /** * Pattern-matches on an array, handling empty and non-empty cases separately. * * **When to use** * * Use when you need to branch on whether an array is empty. * * **Details** * * `onNonEmpty` receives a `NonEmptyArray` for mutable arrays and a * `NonEmptyReadonlyArray` otherwise. Data-last calls default to the readonly * callback, so the returned function still accepts `ReadonlyArray`. Supports * both data-first and data-last usage. * * **Example** (Branching on emptiness) * * ```ts import.meta.vitest * import { Array } from "effect" * * const describe = Array.match({ * onEmpty: () => "empty", * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}` * }) * * describe([]) // => "empty" * describe([1, 2, 3]) // => "head: 1, tail: 2" * ``` * * @see {@link matchLeft} — destructures into head + tail * @see {@link matchRight} — destructures into init + last * * @stability stable * @category pattern matching * @since 2.0.0 */ (options: { readonly onEmpty: LazyArg; readonly onNonEmpty: (self: NonEmptyReadonlyArray) => C; }): (self: ReadonlyArray) => B | C; /** * Pattern-matches on an array, handling empty and non-empty cases separately. * * **When to use** * * Use when you need to branch on whether an array is empty. * * **Details** * * `onNonEmpty` receives a `NonEmptyArray` for mutable arrays and a * `NonEmptyReadonlyArray` otherwise. Data-last calls default to the readonly * callback, so the returned function still accepts `ReadonlyArray`. Supports * both data-first and data-last usage. * * **Example** (Branching on emptiness) * * ```ts import.meta.vitest * import { Array } from "effect" * * const describe = Array.match({ * onEmpty: () => "empty", * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}` * }) * * describe([]) // => "empty" * describe([1, 2, 3]) // => "head: 1, tail: 2" * ``` * * @see {@link matchLeft} — destructures into head + tail * @see {@link matchRight} — destructures into init + last * * @stability stable * @category pattern matching * @since 2.0.0 */ (options: { readonly onEmpty: LazyArg; readonly onNonEmpty: (self: NonEmptyArray) => C; }): (self: Array) => B | C; /** * Pattern-matches on an array, handling empty and non-empty cases separately. * * **When to use** * * Use when you need to branch on whether an array is empty. * * **Details** * * `onNonEmpty` receives a `NonEmptyArray` for mutable arrays and a * `NonEmptyReadonlyArray` otherwise. Data-last calls default to the readonly * callback, so the returned function still accepts `ReadonlyArray`. Supports * both data-first and data-last usage. * * **Example** (Branching on emptiness) * * ```ts import.meta.vitest * import { Array } from "effect" * * const describe = Array.match({ * onEmpty: () => "empty", * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}` * }) * * describe([]) // => "empty" * describe([1, 2, 3]) // => "head: 1, tail: 2" * ``` * * @see {@link matchLeft} — destructures into head + tail * @see {@link matchRight} — destructures into init + last * * @stability stable * @category pattern matching * @since 2.0.0 */ (self: Array, options: { readonly onEmpty: LazyArg; readonly onNonEmpty: (self: NonEmptyArray) => C; }): B | C; /** * Pattern-matches on an array, handling empty and non-empty cases separately. * * **When to use** * * Use when you need to branch on whether an array is empty. * * **Details** * * `onNonEmpty` receives a `NonEmptyArray` for mutable arrays and a * `NonEmptyReadonlyArray` otherwise. Data-last calls default to the readonly * callback, so the returned function still accepts `ReadonlyArray`. Supports * both data-first and data-last usage. * * **Example** (Branching on emptiness) * * ```ts import.meta.vitest * import { Array } from "effect" * * const describe = Array.match({ * onEmpty: () => "empty", * onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}` * }) * * describe([]) // => "empty" * describe([1, 2, 3]) // => "head: 1, tail: 2" * ``` * * @see {@link matchLeft} — destructures into head + tail * @see {@link matchRight} — destructures into init + last * * @stability stable * @category pattern matching * @since 2.0.0 */ (self: ReadonlyArray, options: { readonly onEmpty: LazyArg; readonly onNonEmpty: (self: NonEmptyReadonlyArray) => C; }): B | C; }; /** * Pattern-matches on an array from the left, providing the first element and * the remaining elements separately. * * **When to use** * * Use when you need to branch on an array and handle the non-empty case as the * first element plus the remaining elements. * * **Details** * * `onNonEmpty` receives `(head, tail)` where `tail` is the rest of the array. * * **Example** (Destructuring head and tail) * * ```ts import.meta.vitest * import { Array } from "effect" * * const matchLeft = Array.matchLeft({ * onEmpty: () => "empty", * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}` * }) * * matchLeft([]) // => "empty" * matchLeft([1, 2, 3]) // => "head: 1, tail: 2" * ``` * * @see {@link match} — receives the full non-empty array * @see {@link matchRight} — destructures into init + last * * @stability stable * @category pattern matching * @since 2.0.0 */ export declare const matchLeft: { /** * Pattern-matches on an array from the left, providing the first element and * the remaining elements separately. * * **When to use** * * Use when you need to branch on an array and handle the non-empty case as the * first element plus the remaining elements. * * **Details** * * `onNonEmpty` receives `(head, tail)` where `tail` is the rest of the array. * * **Example** (Destructuring head and tail) * * ```ts import.meta.vitest * import { Array } from "effect" * * const matchLeft = Array.matchLeft({ * onEmpty: () => "empty", * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}` * }) * * matchLeft([]) // => "empty" * matchLeft([1, 2, 3]) // => "head: 1, tail: 2" * ``` * * @see {@link match} — receives the full non-empty array * @see {@link matchRight} — destructures into init + last * * @stability stable * @category pattern matching * @since 2.0.0 */ (options: { readonly onEmpty: LazyArg; readonly onNonEmpty: (head: A, tail: Array) => C; }): (self: ReadonlyArray) => B | C; /** * Pattern-matches on an array from the left, providing the first element and * the remaining elements separately. * * **When to use** * * Use when you need to branch on an array and handle the non-empty case as the * first element plus the remaining elements. * * **Details** * * `onNonEmpty` receives `(head, tail)` where `tail` is the rest of the array. * * **Example** (Destructuring head and tail) * * ```ts import.meta.vitest * import { Array } from "effect" * * const matchLeft = Array.matchLeft({ * onEmpty: () => "empty", * onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}` * }) * * matchLeft([]) // => "empty" * matchLeft([1, 2, 3]) // => "head: 1, tail: 2" * ``` * * @see {@link match} — receives the full non-empty array * @see {@link matchRight} — destructures into init + last * * @stability stable * @category pattern matching * @since 2.0.0 */ (self: ReadonlyArray, options: { readonly onEmpty: LazyArg; readonly onNonEmpty: (head: A, tail: Array) => C; }): B | C; }; /** * Pattern-matches on an array from the right, providing all elements except the * last and the last element separately. * * **When to use** * * Use when you need to branch on an array and handle the non-empty case as the * elements before the last plus the last element. * * **Details** * * `onNonEmpty` receives `(init, last)` where `init` is everything but the last element. * * **Example** (Destructuring init and last) * * ```ts import.meta.vitest * import { Array } from "effect" * * const matchRight = Array.matchRight({ * onEmpty: () => "empty", * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}` * }) * * matchRight([]) // => "empty" * matchRight([1, 2, 3]) // => "init: 2, last: 3" * ``` * * @see {@link match} — receives the full non-empty array * @see {@link matchLeft} — destructures into head + tail * * @stability stable * @category pattern matching * @since 2.0.0 */ export declare const matchRight: { /** * Pattern-matches on an array from the right, providing all elements except the * last and the last element separately. * * **When to use** * * Use when you need to branch on an array and handle the non-empty case as the * elements before the last plus the last element. * * **Details** * * `onNonEmpty` receives `(init, last)` where `init` is everything but the last element. * * **Example** (Destructuring init and last) * * ```ts import.meta.vitest * import { Array } from "effect" * * const matchRight = Array.matchRight({ * onEmpty: () => "empty", * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}` * }) * * matchRight([]) // => "empty" * matchRight([1, 2, 3]) // => "init: 2, last: 3" * ``` * * @see {@link match} — receives the full non-empty array * @see {@link matchLeft} — destructures into head + tail * * @stability stable * @category pattern matching * @since 2.0.0 */ (options: { readonly onEmpty: LazyArg; readonly onNonEmpty: (init: Array, last: A) => C; }): (self: ReadonlyArray) => B | C; /** * Pattern-matches on an array from the right, providing all elements except the * last and the last element separately. * * **When to use** * * Use when you need to branch on an array and handle the non-empty case as the * elements before the last plus the last element. * * **Details** * * `onNonEmpty` receives `(init, last)` where `init` is everything but the last element. * * **Example** (Destructuring init and last) * * ```ts import.meta.vitest * import { Array } from "effect" * * const matchRight = Array.matchRight({ * onEmpty: () => "empty", * onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}` * }) * * matchRight([]) // => "empty" * matchRight([1, 2, 3]) // => "init: 2, last: 3" * ``` * * @see {@link match} — receives the full non-empty array * @see {@link matchLeft} — destructures into head + tail * * @stability stable * @category pattern matching * @since 2.0.0 */ (self: ReadonlyArray, options: { readonly onEmpty: LazyArg; readonly onNonEmpty: (init: Array, last: A) => C; }): B | C; }; /** * Adds a single element to the front of an iterable, returning a `NonEmptyArray`. * * **When to use** * * Use when you need to guarantee a non-empty result after adding a required * leading value. * * **Example** (Prepending an element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.prepend([2, 3, 4], 1) // => [1, 2, 3, 4] * ``` * * @see {@link append} — add to the end * @see {@link prependAll} — prepend multiple elements * * @stability stable * @category combining * @since 2.0.0 */ export declare const prepend: { /** * Adds a single element to the front of an iterable, returning a `NonEmptyArray`. * * **When to use** * * Use when you need to guarantee a non-empty result after adding a required * leading value. * * **Example** (Prepending an element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.prepend([2, 3, 4], 1) // => [1, 2, 3, 4] * ``` * * @see {@link append} — add to the end * @see {@link prependAll} — prepend multiple elements * * @stability stable * @category combining * @since 2.0.0 */ (head: B): (self: Iterable) => NonEmptyArray; /** * Adds a single element to the front of an iterable, returning a `NonEmptyArray`. * * **When to use** * * Use when you need to guarantee a non-empty result after adding a required * leading value. * * **Example** (Prepending an element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.prepend([2, 3, 4], 1) // => [1, 2, 3, 4] * ``` * * @see {@link append} — add to the end * @see {@link prependAll} — prepend multiple elements * * @stability stable * @category combining * @since 2.0.0 */ (self: Iterable, head: B): NonEmptyArray; }; /** * Prepends all elements from a prefix iterable to the front of an array. * * **When to use** * * Use to prepend multiple elements from an iterable to the front of an array. * * **Details** * * If either input is non-empty, the result is a `NonEmptyArray`. * * **Example** (Prepending multiple elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.prependAll([2, 3], [0, 1]) // => [0, 1, 2, 3] * ``` * * @see {@link prepend} — add a single element to the front * @see {@link appendAll} — add elements to the end * * @stability stable * @category combining * @since 2.0.0 */ export declare const prependAll: { /** * Prepends all elements from a prefix iterable to the front of an array. * * **When to use** * * Use to prepend multiple elements from an iterable to the front of an array. * * **Details** * * If either input is non-empty, the result is a `NonEmptyArray`. * * **Example** (Prepending multiple elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.prependAll([2, 3], [0, 1]) // => [0, 1, 2, 3] * ``` * * @see {@link prepend} — add a single element to the front * @see {@link appendAll} — add elements to the end * * @stability stable * @category combining * @since 2.0.0 */ , T extends Iterable>(that: T): (self: S) => ReadonlyArray.OrNonEmpty | ReadonlyArray.Infer>; /** * Prepends all elements from a prefix iterable to the front of an array. * * **When to use** * * Use to prepend multiple elements from an iterable to the front of an array. * * **Details** * * If either input is non-empty, the result is a `NonEmptyArray`. * * **Example** (Prepending multiple elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.prependAll([2, 3], [0, 1]) // => [0, 1, 2, 3] * ``` * * @see {@link prepend} — add a single element to the front * @see {@link appendAll} — add elements to the end * * @stability stable * @category combining * @since 2.0.0 */ (self: Iterable, that: NonEmptyReadonlyArray): NonEmptyArray; /** * Prepends all elements from a prefix iterable to the front of an array. * * **When to use** * * Use to prepend multiple elements from an iterable to the front of an array. * * **Details** * * If either input is non-empty, the result is a `NonEmptyArray`. * * **Example** (Prepending multiple elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.prependAll([2, 3], [0, 1]) // => [0, 1, 2, 3] * ``` * * @see {@link prepend} — add a single element to the front * @see {@link appendAll} — add elements to the end * * @stability stable * @category combining * @since 2.0.0 */ (self: NonEmptyReadonlyArray, that: Iterable): NonEmptyArray; /** * Prepends all elements from a prefix iterable to the front of an array. * * **When to use** * * Use to prepend multiple elements from an iterable to the front of an array. * * **Details** * * If either input is non-empty, the result is a `NonEmptyArray`. * * **Example** (Prepending multiple elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.prependAll([2, 3], [0, 1]) // => [0, 1, 2, 3] * ``` * * @see {@link prepend} — add a single element to the front * @see {@link appendAll} — add elements to the end * * @stability stable * @category combining * @since 2.0.0 */ (self: Iterable, that: Iterable): Array; }; /** * Adds a single element to the end of an iterable, returning a `NonEmptyArray`. * * **When to use** * * Use when you need to guarantee a non-empty result after adding a required * trailing value. * * **Example** (Appending an element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.append([1, 2, 3], 4) // => [1, 2, 3, 4] * ``` * * @see {@link prepend} — add to the front * @see {@link appendAll} — append multiple elements * * @stability stable * @category combining * @since 2.0.0 */ export declare const append: { /** * Adds a single element to the end of an iterable, returning a `NonEmptyArray`. * * **When to use** * * Use when you need to guarantee a non-empty result after adding a required * trailing value. * * **Example** (Appending an element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.append([1, 2, 3], 4) // => [1, 2, 3, 4] * ``` * * @see {@link prepend} — add to the front * @see {@link appendAll} — append multiple elements * * @stability stable * @category combining * @since 2.0.0 */ (last: B): (self: Iterable) => NonEmptyArray; /** * Adds a single element to the end of an iterable, returning a `NonEmptyArray`. * * **When to use** * * Use when you need to guarantee a non-empty result after adding a required * trailing value. * * **Example** (Appending an element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.append([1, 2, 3], 4) // => [1, 2, 3, 4] * ``` * * @see {@link prepend} — add to the front * @see {@link appendAll} — append multiple elements * * @stability stable * @category combining * @since 2.0.0 */ (self: Iterable, last: B): NonEmptyArray; }; /** * Concatenates two iterables into a single array. * * **When to use** * * Use to combine two iterable inputs into a new array with the second input's * elements after the first. * * **Details** * * If either input is non-empty, the result is a `NonEmptyArray`. * * **Example** (Concatenating arrays) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.appendAll([1, 2], [3, 4]) // => [1, 2, 3, 4] * ``` * * @see {@link append} — add a single element to the end * @see {@link prependAll} — add elements to the front * * @stability stable * @category combining * @since 2.0.0 */ export declare const appendAll: { /** * Concatenates two iterables into a single array. * * **When to use** * * Use to combine two iterable inputs into a new array with the second input's * elements after the first. * * **Details** * * If either input is non-empty, the result is a `NonEmptyArray`. * * **Example** (Concatenating arrays) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.appendAll([1, 2], [3, 4]) // => [1, 2, 3, 4] * ``` * * @see {@link append} — add a single element to the end * @see {@link prependAll} — add elements to the front * * @stability stable * @category combining * @since 2.0.0 */ , T extends Iterable>(that: T): (self: S) => ReadonlyArray.OrNonEmpty | ReadonlyArray.Infer>; /** * Concatenates two iterables into a single array. * * **When to use** * * Use to combine two iterable inputs into a new array with the second input's * elements after the first. * * **Details** * * If either input is non-empty, the result is a `NonEmptyArray`. * * **Example** (Concatenating arrays) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.appendAll([1, 2], [3, 4]) // => [1, 2, 3, 4] * ``` * * @see {@link append} — add a single element to the end * @see {@link prependAll} — add elements to the front * * @stability stable * @category combining * @since 2.0.0 */ (self: Iterable, that: NonEmptyReadonlyArray): NonEmptyArray; /** * Concatenates two iterables into a single array. * * **When to use** * * Use to combine two iterable inputs into a new array with the second input's * elements after the first. * * **Details** * * If either input is non-empty, the result is a `NonEmptyArray`. * * **Example** (Concatenating arrays) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.appendAll([1, 2], [3, 4]) // => [1, 2, 3, 4] * ``` * * @see {@link append} — add a single element to the end * @see {@link prependAll} — add elements to the front * * @stability stable * @category combining * @since 2.0.0 */ (self: NonEmptyReadonlyArray, that: Iterable): NonEmptyArray; /** * Concatenates two iterables into a single array. * * **When to use** * * Use to combine two iterable inputs into a new array with the second input's * elements after the first. * * **Details** * * If either input is non-empty, the result is a `NonEmptyArray`. * * **Example** (Concatenating arrays) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.appendAll([1, 2], [3, 4]) // => [1, 2, 3, 4] * ``` * * @see {@link append} — add a single element to the end * @see {@link prependAll} — add elements to the front * * @stability stable * @category combining * @since 2.0.0 */ (self: Iterable, that: Iterable): Array; }; /** * Folds left-to-right while keeping every intermediate accumulator value. * * **When to use** * * Use to compute a running accumulator where each intermediate value is needed. * * **Details** * * The output length is `input.length + 1` because it starts with the initial * value. The result is always a `NonEmptyArray`. Use `reduce` if you only need * the final accumulated value. * * **Example** (Running totals) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.scan([1, 2, 3, 4], 0, (acc, value) => acc + value) // => [0, 1, 3, 6, 10] * ``` * * @see {@link scanRight} — right-to-left scan * @see {@link reduce} — fold without intermediate values * * @stability stable * @category folding * @since 2.0.0 */ export declare const scan: { /** * Folds left-to-right while keeping every intermediate accumulator value. * * **When to use** * * Use to compute a running accumulator where each intermediate value is needed. * * **Details** * * The output length is `input.length + 1` because it starts with the initial * value. The result is always a `NonEmptyArray`. Use `reduce` if you only need * the final accumulated value. * * **Example** (Running totals) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.scan([1, 2, 3, 4], 0, (acc, value) => acc + value) // => [0, 1, 3, 6, 10] * ``` * * @see {@link scanRight} — right-to-left scan * @see {@link reduce} — fold without intermediate values * * @stability stable * @category folding * @since 2.0.0 */ (b: B, f: (b: B, a: A) => B): (self: Iterable) => NonEmptyArray; /** * Folds left-to-right while keeping every intermediate accumulator value. * * **When to use** * * Use to compute a running accumulator where each intermediate value is needed. * * **Details** * * The output length is `input.length + 1` because it starts with the initial * value. The result is always a `NonEmptyArray`. Use `reduce` if you only need * the final accumulated value. * * **Example** (Running totals) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.scan([1, 2, 3, 4], 0, (acc, value) => acc + value) // => [0, 1, 3, 6, 10] * ``` * * @see {@link scanRight} — right-to-left scan * @see {@link reduce} — fold without intermediate values * * @stability stable * @category folding * @since 2.0.0 */ (self: Iterable, b: B, f: (b: B, a: A) => B): NonEmptyArray; }; /** * Folds right-to-left while keeping every intermediate accumulator value. * * **When to use** * * Use to compute a running accumulator from right to left where each intermediate * value is needed. * * **Details** * * The output length is `input.length + 1` because it ends with the initial * value. The result is always a `NonEmptyArray`. * * **Example** (Scanning running totals in reverse) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.scanRight([1, 2, 3, 4], 0, (acc, value) => acc + value) // => [10, 9, 7, 4, 0] * ``` * * @see {@link scan} — left-to-right scan * @see {@link reduceRight} — fold without intermediate values * * @stability stable * @category folding * @since 2.0.0 */ export declare const scanRight: { /** * Folds right-to-left while keeping every intermediate accumulator value. * * **When to use** * * Use to compute a running accumulator from right to left where each intermediate * value is needed. * * **Details** * * The output length is `input.length + 1` because it ends with the initial * value. The result is always a `NonEmptyArray`. * * **Example** (Scanning running totals in reverse) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.scanRight([1, 2, 3, 4], 0, (acc, value) => acc + value) // => [10, 9, 7, 4, 0] * ``` * * @see {@link scan} — left-to-right scan * @see {@link reduceRight} — fold without intermediate values * * @stability stable * @category folding * @since 2.0.0 */ (b: B, f: (b: B, a: A) => B): (self: Iterable) => NonEmptyArray; /** * Folds right-to-left while keeping every intermediate accumulator value. * * **When to use** * * Use to compute a running accumulator from right to left where each intermediate * value is needed. * * **Details** * * The output length is `input.length + 1` because it ends with the initial * value. The result is always a `NonEmptyArray`. * * **Example** (Scanning running totals in reverse) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.scanRight([1, 2, 3, 4], 0, (acc, value) => acc + value) // => [10, 9, 7, 4, 0] * ``` * * @see {@link scan} — left-to-right scan * @see {@link reduceRight} — fold without intermediate values * * @stability stable * @category folding * @since 2.0.0 */ (self: Iterable, b: B, f: (b: B, a: A) => B): NonEmptyArray; }; /** * Checks whether a value is an `Array`. * * **When to use** * * Use to verify a value is a mutable array, narrowing its type to `Array`. * * **Details** * * Acts as a type guard narrowing the input to `Array` and delegates to * `globalThis.Array.isArray`. * * **Example** (Type-guarding an unknown value) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.isArray(null) // => false * Array.isArray([1, 2, 3]) // => true * ``` * * @see {@link isArrayEmpty} — check for an empty array * @see {@link isArrayNonEmpty} — check for a non-empty array * * @stability stable * @category guards * @since 2.0.0 */ export declare const isArray: { /** * Checks whether a value is an `Array`. * * **When to use** * * Use to verify a value is a mutable array, narrowing its type to `Array`. * * **Details** * * Acts as a type guard narrowing the input to `Array` and delegates to * `globalThis.Array.isArray`. * * **Example** (Type-guarding an unknown value) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.isArray(null) // => false * Array.isArray([1, 2, 3]) // => true * ``` * * @see {@link isArrayEmpty} — check for an empty array * @see {@link isArrayNonEmpty} — check for a non-empty array * * @stability stable * @category guards * @since 2.0.0 */ (self: unknown): self is Array; /** * Checks whether a value is an `Array`. * * **When to use** * * Use to verify a value is a mutable array, narrowing its type to `Array`. * * **Details** * * Acts as a type guard narrowing the input to `Array` and delegates to * `globalThis.Array.isArray`. * * **Example** (Type-guarding an unknown value) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.isArray(null) // => false * Array.isArray([1, 2, 3]) // => true * ``` * * @see {@link isArrayEmpty} — check for an empty array * @see {@link isArrayNonEmpty} — check for a non-empty array * * @stability stable * @category guards * @since 2.0.0 */ (self: T): self is Extract>; }; /** * Checks whether a mutable `Array` is empty, narrowing the type to `[]`. * * **Example** (Checking for an empty array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.isArrayEmpty([]) // => true * Array.isArrayEmpty([1, 2, 3]) // => false * ``` * * @see {@link isReadonlyArrayEmpty} — readonly variant * @see {@link isArrayNonEmpty} — opposite check * * @stability stable * @category guards * @since 4.0.0 */ export declare const isArrayEmpty: (self: Array) => self is []; /** * Checks whether a `ReadonlyArray` is empty, narrowing the type to `readonly []`. * * **Example** (Checking for an empty readonly array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.isReadonlyArrayEmpty([]) // => true * Array.isReadonlyArrayEmpty([1, 2, 3]) // => false * ``` * * @see {@link isArrayEmpty} — mutable variant * @see {@link isReadonlyArrayNonEmpty} — opposite check * * @stability stable * @category guards * @since 4.0.0 */ export declare const isReadonlyArrayEmpty: (self: ReadonlyArray) => self is readonly []; /** * Checks whether a mutable `Array` is non-empty, narrowing the type to * `NonEmptyArray`. * * **When to use** * * Use when you need the narrowed value to remain a mutable `Array` after proving * it has at least one element. * * **Example** (Checking for a non-empty array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.isArrayNonEmpty([]) // => false * Array.isArrayNonEmpty([1, 2, 3]) // => true * ``` * * @see {@link isReadonlyArrayNonEmpty} — readonly variant * @see {@link isArrayEmpty} — opposite check * * @stability stable * @category guards * @since 4.0.0 */ export declare const isArrayNonEmpty: (self: Array) => self is NonEmptyArray; /** * Checks whether a `ReadonlyArray` is non-empty, narrowing the type to * `NonEmptyReadonlyArray`. * * **When to use** * * Use when you need to prove a readonly array has at least one element without * requiring mutable array methods afterward. * * **Example** (Checking for a non-empty readonly array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.isReadonlyArrayNonEmpty([]) // => false * Array.isReadonlyArrayNonEmpty([1, 2, 3]) // => true * ``` * * @see {@link isArrayNonEmpty} — mutable variant * @see {@link isReadonlyArrayEmpty} — opposite check * * @stability stable * @category guards * @since 4.0.0 */ export declare const isReadonlyArrayNonEmpty: (self: ReadonlyArray) => self is NonEmptyReadonlyArray; /** * Returns the number of elements in a `ReadonlyArray`. * * **When to use** * * Use when you need length as a composable function rather than a property access. * * **Example** (Getting the length) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.length([1, 2, 3]) // => 3 * ``` * * @stability stable * @category getters * @since 2.0.0 */ export declare const length: (self: ReadonlyArray) => number; /** * Reads an element at the given index safely, returning `Option.some` or * `Option.none` if the index is out of bounds. * * **When to use** * * Use when you need to read an array element by index and handle an * out-of-bounds index as `Option.none`. * * **Details** * * The index is floored to an integer. This never throws. * * **Example** (Accessing indexes safely) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.get([1, 2, 3], 1) // => Option.some(2) * Array.get([1, 2, 3], 10) // => Option.none() * ``` * * @see {@link getUnsafe} for indexed access that throws when the index is out of bounds * @see {@link head} for reading the first element as an `Option` * @see {@link last} for reading the last element as an `Option` * * @stability stable * @category getters * @since 2.0.0 */ export declare const get: { /** * Reads an element at the given index safely, returning `Option.some` or * `Option.none` if the index is out of bounds. * * **When to use** * * Use when you need to read an array element by index and handle an * out-of-bounds index as `Option.none`. * * **Details** * * The index is floored to an integer. This never throws. * * **Example** (Accessing indexes safely) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.get([1, 2, 3], 1) // => Option.some(2) * Array.get([1, 2, 3], 10) // => Option.none() * ``` * * @see {@link getUnsafe} for indexed access that throws when the index is out of bounds * @see {@link head} for reading the first element as an `Option` * @see {@link last} for reading the last element as an `Option` * * @stability stable * @category getters * @since 2.0.0 */ (index: number): (self: ReadonlyArray) => Option.Option; /** * Reads an element at the given index safely, returning `Option.some` or * `Option.none` if the index is out of bounds. * * **When to use** * * Use when you need to read an array element by index and handle an * out-of-bounds index as `Option.none`. * * **Details** * * The index is floored to an integer. This never throws. * * **Example** (Accessing indexes safely) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.get([1, 2, 3], 1) // => Option.some(2) * Array.get([1, 2, 3], 10) // => Option.none() * ``` * * @see {@link getUnsafe} for indexed access that throws when the index is out of bounds * @see {@link head} for reading the first element as an `Option` * @see {@link last} for reading the last element as an `Option` * * @stability stable * @category getters * @since 2.0.0 */ (self: ReadonlyArray, index: number): Option.Option; }; /** * Reads an element at the given index, throwing if the index is out of bounds. * * **When to use** * * Use to read an array element at a known valid index when out-of-bounds would * be a programming error. * * **Details** * * Throws an `Error` with the message `"Index out of bounds: "`. Prefer * `get` for safe access. * * **Example** (Accessing indexes unsafely) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.getUnsafe([1, 2, 3], 1) // => 2 * // Array.getUnsafe([1, 2, 3], 10) // throws Error * ``` * * @see {@link get} — safe version returning `Option` * * @stability stable * @category unsafe * @since 4.0.0 */ export declare const getUnsafe: { /** * Reads an element at the given index, throwing if the index is out of bounds. * * **When to use** * * Use to read an array element at a known valid index when out-of-bounds would * be a programming error. * * **Details** * * Throws an `Error` with the message `"Index out of bounds: "`. Prefer * `get` for safe access. * * **Example** (Accessing indexes unsafely) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.getUnsafe([1, 2, 3], 1) // => 2 * // Array.getUnsafe([1, 2, 3], 10) // throws Error * ``` * * @see {@link get} — safe version returning `Option` * * @stability stable * @category unsafe * @since 4.0.0 */ (index: number): (self: ReadonlyArray) => A; /** * Reads an element at the given index, throwing if the index is out of bounds. * * **When to use** * * Use to read an array element at a known valid index when out-of-bounds would * be a programming error. * * **Details** * * Throws an `Error` with the message `"Index out of bounds: "`. Prefer * `get` for safe access. * * **Example** (Accessing indexes unsafely) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.getUnsafe([1, 2, 3], 1) // => 2 * // Array.getUnsafe([1, 2, 3], 10) // throws Error * ``` * * @see {@link get} — safe version returning `Option` * * @stability stable * @category unsafe * @since 4.0.0 */ (self: ReadonlyArray, index: number): A; }; /** * Splits a non-empty array into its first element and the remaining elements. * * **When to use** * * Use when you have a `NonEmptyReadonlyArray` and need both its first element * and the remaining elements as separate values. * * **Details** * * Returns a tuple `[head, tail]` and requires a `NonEmptyReadonlyArray`. * * **Example** (Destructuring head and tail) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.unprepend([1, 2, 3, 4]) // => [1, [2, 3, 4]] * ``` * * @see {@link unappend} for splitting a non-empty array into init and last * @see {@link headNonEmpty} for getting only the first element * @see {@link tailNonEmpty} for getting only the elements after the first * * @stability stable * @category splitting * @since 2.0.0 */ export declare const unprepend: (self: NonEmptyReadonlyArray) => [firstElement: A, remainingElements: Array]; /** * Splits a non-empty array into all elements except the last, and the last * element. * * **When to use** * * Use when you need to split a non-empty array into the elements before the * last element and the last element. * * **Details** * * Returns a tuple `[init, last]` and requires a `NonEmptyReadonlyArray`. * * **Example** (Destructuring init and last) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.unappend([1, 2, 3, 4]) // => [[1, 2, 3], 4] * ``` * * @see {@link unprepend} for splitting a non-empty array into head and tail * @see {@link initNonEmpty} for getting only the elements before the last * @see {@link lastNonEmpty} for getting only the last element * * @stability stable * @category splitting * @since 2.0.0 */ export declare const unappend: (self: NonEmptyReadonlyArray) => [arrayWithoutLastElement: Array, lastElement: A]; /** * Returns the first element of an array safely wrapped in `Option.some`, or * `Option.none` if the array is empty. * * **When to use** * * Use to safely get the first element of an array that may be empty. * * **Example** (Getting the first element) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.head([1, 2, 3]) // => Option.some(1) * Array.head([]) // => Option.none() * ``` * * @see {@link headNonEmpty} — direct access when array is known non-empty * @see {@link last} — get the last element * * @stability stable * @category getters * @since 2.0.0 */ export declare const head: (self: ReadonlyArray) => Option.Option; /** * Returns the first element of a `NonEmptyReadonlyArray` directly (no `Option` * wrapper). * * **When to use** * * Use to get the first element without `Option` wrapping when the array is known * to be non-empty. * * **Example** (Getting the head of a non-empty array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.headNonEmpty([1, 2, 3, 4]) // => 1 * ``` * * @see {@link head} — safe version for possibly-empty arrays * * @stability stable * @category getters * @since 2.0.0 */ export declare const headNonEmpty: (self: NonEmptyReadonlyArray) => A; /** * Returns the last element of an array safely wrapped in `Option.some`, or * `Option.none` if the array is empty. * * **When to use** * * Use to safely get the last element of an array that may be empty. * * **Example** (Getting the last element) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.last([1, 2, 3]) // => Option.some(3) * Array.last([]) // => Option.none() * ``` * * @see {@link lastNonEmpty} — direct access when array is known non-empty * @see {@link head} — get the first element * * @stability stable * @category getters * @since 2.0.0 */ export declare const last: (self: ReadonlyArray) => Option.Option; /** * Returns the last element of a `NonEmptyReadonlyArray` directly (no `Option` * wrapper). * * **When to use** * * Use to get the last element without `Option` wrapping when the array is known * to be non-empty. * * **Example** (Getting the last of a non-empty array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.lastNonEmpty([1, 2, 3, 4]) // => 4 * ``` * * @see {@link last} — safe version for possibly-empty arrays * * @stability stable * @category getters * @since 2.0.0 */ export declare const lastNonEmpty: (self: NonEmptyReadonlyArray) => A; /** * Returns all elements except the first safely, wrapped in an `Option`. * * **When to use** * * Use to safely get all elements after the first when the iterable may be empty. * * **Details** * * Allocates a new array via `slice(1)`. Empty inputs return `Option.none()`. * * **Example** (Getting the tail) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.tail([1, 2, 3, 4]) // => Option.some([2, 3, 4]) * Array.tail([]) // => Option.none() * ``` * * @see {@link tailNonEmpty} — when the array is known non-empty * @see {@link init} — all elements except the last * * @stability stable * @category getters * @since 2.0.0 */ export declare function tail(self: Iterable): Option.Option>; /** * Returns all elements except the first of a `NonEmptyReadonlyArray`. * * **When to use** * * Use to get all elements after the first when the array is known to be non-empty. * * **Example** (Getting the tail of a non-empty array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.tailNonEmpty([1, 2, 3, 4]) // => [2, 3, 4] * ``` * * @see {@link tail} — safe version for possibly-empty arrays * @see {@link initNonEmpty} — all elements except the last * * @stability stable * @category getters * @since 2.0.0 */ export declare const tailNonEmpty: (self: NonEmptyReadonlyArray) => Array; /** * Returns all elements except the last safely, wrapped in an `Option`. * * **When to use** * * Use to safely get all elements before the last when the iterable may be empty. * * **Details** * * Allocates a new array via `slice(0, -1)`. Empty inputs return * `Option.none()`. * * **Example** (Getting init) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.init([1, 2, 3, 4]) // => Option.some([1, 2, 3]) * Array.init([]) // => Option.none() * ``` * * @see {@link initNonEmpty} — when the array is known non-empty * @see {@link tail} — all elements except the first * * @stability stable * @category getters * @since 2.0.0 */ export declare function init(self: Iterable): Option.Option>; /** * Returns all elements except the last of a `NonEmptyReadonlyArray`. * * **When to use** * * Use to get all elements before the last when the array is known to be non-empty. * * **Example** (Getting init of a non-empty array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.initNonEmpty([1, 2, 3, 4]) // => [1, 2, 3] * ``` * * @see {@link init} — safe version for possibly-empty arrays * @see {@link tailNonEmpty} — all elements except the first * * @stability stable * @category getters * @since 2.0.0 */ export declare const initNonEmpty: (self: NonEmptyReadonlyArray) => Array; /** * Keeps the first `n` elements, creating a new array. * * **When to use** * * Use to keep up to the first `n` elements from an iterable as a new array. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`. * Returns an empty array when `n <= 0`. * * **Example** (Taking from the start) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.take([1, 2, 3, 4, 5], 3) // => [1, 2, 3] * ``` * * @see {@link takeRight} for keeping elements from the end * @see {@link takeWhile} for keeping an initial prefix while a predicate holds * @see {@link drop} for removing elements from the start * * @stability stable * @category getters * @since 2.0.0 */ export declare const take: { /** * Keeps the first `n` elements, creating a new array. * * **When to use** * * Use to keep up to the first `n` elements from an iterable as a new array. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`. * Returns an empty array when `n <= 0`. * * **Example** (Taking from the start) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.take([1, 2, 3, 4, 5], 3) // => [1, 2, 3] * ``` * * @see {@link takeRight} for keeping elements from the end * @see {@link takeWhile} for keeping an initial prefix while a predicate holds * @see {@link drop} for removing elements from the start * * @stability stable * @category getters * @since 2.0.0 */ (n: number): (self: Iterable) => Array; /** * Keeps the first `n` elements, creating a new array. * * **When to use** * * Use to keep up to the first `n` elements from an iterable as a new array. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`. * Returns an empty array when `n <= 0`. * * **Example** (Taking from the start) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.take([1, 2, 3, 4, 5], 3) // => [1, 2, 3] * ``` * * @see {@link takeRight} for keeping elements from the end * @see {@link takeWhile} for keeping an initial prefix while a predicate holds * @see {@link drop} for removing elements from the start * * @stability stable * @category getters * @since 2.0.0 */ (self: Iterable, n: number): Array; }; /** * Keeps the last `n` elements, creating a new array. * * **When to use** * * Use to keep the last `n` elements of an iterable. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`. * Returns an empty array when `n <= 0`. * * **Example** (Taking from the end) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.takeRight([1, 2, 3, 4, 5], 3) // => [3, 4, 5] * ``` * * @see {@link take} — keep from the start * @see {@link dropRight} — remove from the end * * @stability stable * @category getters * @since 2.0.0 */ export declare const takeRight: { /** * Keeps the last `n` elements, creating a new array. * * **When to use** * * Use to keep the last `n` elements of an iterable. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`. * Returns an empty array when `n <= 0`. * * **Example** (Taking from the end) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.takeRight([1, 2, 3, 4, 5], 3) // => [3, 4, 5] * ``` * * @see {@link take} — keep from the start * @see {@link dropRight} — remove from the end * * @stability stable * @category getters * @since 2.0.0 */ (n: number): (self: Iterable) => Array; /** * Keeps the last `n` elements, creating a new array. * * **When to use** * * Use to keep the last `n` elements of an iterable. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`. * Returns an empty array when `n <= 0`. * * **Example** (Taking from the end) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.takeRight([1, 2, 3, 4, 5], 3) // => [3, 4, 5] * ``` * * @see {@link take} — keep from the start * @see {@link dropRight} — remove from the end * * @stability stable * @category getters * @since 2.0.0 */ (self: Iterable, n: number): Array; }; /** * Takes elements from the start while the predicate holds, stopping at the * first element that fails. * * **When to use** * * Use to keep the leading elements of an iterable while each element satisfies * a predicate, returning the retained prefix as an array. * * **Details** * * Supports refinements for type narrowing. The predicate receives * `(element, index)`. * * **Example** (Taking while condition holds) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.takeWhile([1, 3, 2, 4, 1, 2], (x) => x < 4) // => [1, 3, 2] * ``` * * @see {@link take} for keeping a fixed number of leading elements * @see {@link dropWhile} for removing the matching prefix and keeping the rest * @see {@link span} for splitting the matching prefix from the remaining elements * * @stability stable * @category getters * @since 2.0.0 */ export declare const takeWhile: { /** * Takes elements from the start while the predicate holds, stopping at the * first element that fails. * * **When to use** * * Use to keep the leading elements of an iterable while each element satisfies * a predicate, returning the retained prefix as an array. * * **Details** * * Supports refinements for type narrowing. The predicate receives * `(element, index)`. * * **Example** (Taking while condition holds) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.takeWhile([1, 3, 2, 4, 1, 2], (x) => x < 4) // => [1, 3, 2] * ``` * * @see {@link take} for keeping a fixed number of leading elements * @see {@link dropWhile} for removing the matching prefix and keeping the rest * @see {@link span} for splitting the matching prefix from the remaining elements * * @stability stable * @category getters * @since 2.0.0 */ (refinement: (a: NoInfer, i: number) => a is B): (self: Iterable) => Array; /** * Takes elements from the start while the predicate holds, stopping at the * first element that fails. * * **When to use** * * Use to keep the leading elements of an iterable while each element satisfies * a predicate, returning the retained prefix as an array. * * **Details** * * Supports refinements for type narrowing. The predicate receives * `(element, index)`. * * **Example** (Taking while condition holds) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.takeWhile([1, 3, 2, 4, 1, 2], (x) => x < 4) // => [1, 3, 2] * ``` * * @see {@link take} for keeping a fixed number of leading elements * @see {@link dropWhile} for removing the matching prefix and keeping the rest * @see {@link span} for splitting the matching prefix from the remaining elements * * @stability stable * @category getters * @since 2.0.0 */ (predicate: (a: NoInfer, i: number) => boolean): (self: Iterable) => Array; /** * Takes elements from the start while the predicate holds, stopping at the * first element that fails. * * **When to use** * * Use to keep the leading elements of an iterable while each element satisfies * a predicate, returning the retained prefix as an array. * * **Details** * * Supports refinements for type narrowing. The predicate receives * `(element, index)`. * * **Example** (Taking while condition holds) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.takeWhile([1, 3, 2, 4, 1, 2], (x) => x < 4) // => [1, 3, 2] * ``` * * @see {@link take} for keeping a fixed number of leading elements * @see {@link dropWhile} for removing the matching prefix and keeping the rest * @see {@link span} for splitting the matching prefix from the remaining elements * * @stability stable * @category getters * @since 2.0.0 */ (self: Iterable, refinement: (a: A, i: number) => a is B): Array; /** * Takes elements from the start while the predicate holds, stopping at the * first element that fails. * * **When to use** * * Use to keep the leading elements of an iterable while each element satisfies * a predicate, returning the retained prefix as an array. * * **Details** * * Supports refinements for type narrowing. The predicate receives * `(element, index)`. * * **Example** (Taking while condition holds) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.takeWhile([1, 3, 2, 4, 1, 2], (x) => x < 4) // => [1, 3, 2] * ``` * * @see {@link take} for keeping a fixed number of leading elements * @see {@link dropWhile} for removing the matching prefix and keeping the rest * @see {@link span} for splitting the matching prefix from the remaining elements * * @stability stable * @category getters * @since 2.0.0 */ (self: Iterable, predicate: (a: A, i: number) => boolean): Array; }; /** * Takes elements from the start while a `Filter` succeeds, collecting transformed values. * * **When to use** * * Use when you need to take a prefix from an iterable while a function can * successfully extract or transform elements, stopping at the first element * that produces a failure result. * * **Details** * * The filter receives `(element, index)` and processing stops at the first * filter failure. * * @see {@link takeWhile} for taking a prefix based on a boolean predicate * * @stability stable * @category getters * @since 4.0.0 */ export declare const takeWhileFilter: { /** * Takes elements from the start while a `Filter` succeeds, collecting transformed values. * * **When to use** * * Use when you need to take a prefix from an iterable while a function can * successfully extract or transform elements, stopping at the first element * that produces a failure result. * * **Details** * * The filter receives `(element, index)` and processing stops at the first * filter failure. * * @see {@link takeWhile} for taking a prefix based on a boolean predicate * * @stability stable * @category getters * @since 4.0.0 */ (f: (input: NoInfer, i: number) => Result.Result): (self: Iterable) => Array; /** * Takes elements from the start while a `Filter` succeeds, collecting transformed values. * * **When to use** * * Use when you need to take a prefix from an iterable while a function can * successfully extract or transform elements, stopping at the first element * that produces a failure result. * * **Details** * * The filter receives `(element, index)` and processing stops at the first * filter failure. * * @see {@link takeWhile} for taking a prefix based on a boolean predicate * * @stability stable * @category getters * @since 4.0.0 */ (self: Iterable, f: (input: NoInfer, i: number) => Result.Result): Array; }; /** * Splits an iterable into two arrays: the longest prefix where the predicate * holds, and the remaining elements. * * **When to use** * * Use when you need both the longest predicate-matching prefix and the * remaining elements. * * **Details** * * Equivalent to `[takeWhile(pred), dropWhile(pred)]`, but more efficient * because it runs in a single pass. Supports refinements for type narrowing of * the prefix. * * **Example** (Splitting at predicate boundary) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.span([1, 3, 2, 4, 5], (x) => x % 2 === 1) // => [[1, 3], [2, 4, 5]] * ``` * * @see {@link takeWhile} for keeping only the matching prefix * @see {@link dropWhile} for keeping only the elements after the matching prefix * @see {@link splitWhere} for splitting at the first element that satisfies a predicate * * @stability stable * @category splitting * @since 2.0.0 */ export declare const span: { /** * Splits an iterable into two arrays: the longest prefix where the predicate * holds, and the remaining elements. * * **When to use** * * Use when you need both the longest predicate-matching prefix and the * remaining elements. * * **Details** * * Equivalent to `[takeWhile(pred), dropWhile(pred)]`, but more efficient * because it runs in a single pass. Supports refinements for type narrowing of * the prefix. * * **Example** (Splitting at predicate boundary) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.span([1, 3, 2, 4, 5], (x) => x % 2 === 1) // => [[1, 3], [2, 4, 5]] * ``` * * @see {@link takeWhile} for keeping only the matching prefix * @see {@link dropWhile} for keeping only the elements after the matching prefix * @see {@link splitWhere} for splitting at the first element that satisfies a predicate * * @stability stable * @category splitting * @since 2.0.0 */ (refinement: (a: NoInfer, i: number) => a is B): (self: Iterable) => [init: Array, rest: Array>]; /** * Splits an iterable into two arrays: the longest prefix where the predicate * holds, and the remaining elements. * * **When to use** * * Use when you need both the longest predicate-matching prefix and the * remaining elements. * * **Details** * * Equivalent to `[takeWhile(pred), dropWhile(pred)]`, but more efficient * because it runs in a single pass. Supports refinements for type narrowing of * the prefix. * * **Example** (Splitting at predicate boundary) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.span([1, 3, 2, 4, 5], (x) => x % 2 === 1) // => [[1, 3], [2, 4, 5]] * ``` * * @see {@link takeWhile} for keeping only the matching prefix * @see {@link dropWhile} for keeping only the elements after the matching prefix * @see {@link splitWhere} for splitting at the first element that satisfies a predicate * * @stability stable * @category splitting * @since 2.0.0 */ (predicate: (a: NoInfer, i: number) => boolean): (self: Iterable) => [init: Array, rest: Array]; /** * Splits an iterable into two arrays: the longest prefix where the predicate * holds, and the remaining elements. * * **When to use** * * Use when you need both the longest predicate-matching prefix and the * remaining elements. * * **Details** * * Equivalent to `[takeWhile(pred), dropWhile(pred)]`, but more efficient * because it runs in a single pass. Supports refinements for type narrowing of * the prefix. * * **Example** (Splitting at predicate boundary) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.span([1, 3, 2, 4, 5], (x) => x % 2 === 1) // => [[1, 3], [2, 4, 5]] * ``` * * @see {@link takeWhile} for keeping only the matching prefix * @see {@link dropWhile} for keeping only the elements after the matching prefix * @see {@link splitWhere} for splitting at the first element that satisfies a predicate * * @stability stable * @category splitting * @since 2.0.0 */ (self: Iterable, refinement: (a: A, i: number) => a is B): [init: Array, rest: Array>]; /** * Splits an iterable into two arrays: the longest prefix where the predicate * holds, and the remaining elements. * * **When to use** * * Use when you need both the longest predicate-matching prefix and the * remaining elements. * * **Details** * * Equivalent to `[takeWhile(pred), dropWhile(pred)]`, but more efficient * because it runs in a single pass. Supports refinements for type narrowing of * the prefix. * * **Example** (Splitting at predicate boundary) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.span([1, 3, 2, 4, 5], (x) => x % 2 === 1) // => [[1, 3], [2, 4, 5]] * ``` * * @see {@link takeWhile} for keeping only the matching prefix * @see {@link dropWhile} for keeping only the elements after the matching prefix * @see {@link splitWhere} for splitting at the first element that satisfies a predicate * * @stability stable * @category splitting * @since 2.0.0 */ (self: Iterable, predicate: (a: A, i: number) => boolean): [init: Array, rest: Array]; }; /** * Removes the first `n` elements, creating a new array. * * **When to use** * * Use to keep the suffix of an iterable after skipping a fixed number of * leading elements. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`. * When `n <= 0`, this returns a copy of the full array. * * **Example** (Dropping from the start) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.drop([1, 2, 3, 4, 5], 2) // => [3, 4, 5] * ``` * * @see {@link dropRight} for removing a fixed number of elements from the end * @see {@link dropWhile} for removing a prefix based on a predicate instead of a fixed count * @see {@link take} for keeping a fixed number of elements from the start * * @stability stable * @category getters * @since 2.0.0 */ export declare const drop: { /** * Removes the first `n` elements, creating a new array. * * **When to use** * * Use to keep the suffix of an iterable after skipping a fixed number of * leading elements. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`. * When `n <= 0`, this returns a copy of the full array. * * **Example** (Dropping from the start) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.drop([1, 2, 3, 4, 5], 2) // => [3, 4, 5] * ``` * * @see {@link dropRight} for removing a fixed number of elements from the end * @see {@link dropWhile} for removing a prefix based on a predicate instead of a fixed count * @see {@link take} for keeping a fixed number of elements from the start * * @stability stable * @category getters * @since 2.0.0 */ (n: number): (self: Iterable) => Array; /** * Removes the first `n` elements, creating a new array. * * **When to use** * * Use to keep the suffix of an iterable after skipping a fixed number of * leading elements. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`. * When `n <= 0`, this returns a copy of the full array. * * **Example** (Dropping from the start) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.drop([1, 2, 3, 4, 5], 2) // => [3, 4, 5] * ``` * * @see {@link dropRight} for removing a fixed number of elements from the end * @see {@link dropWhile} for removing a prefix based on a predicate instead of a fixed count * @see {@link take} for keeping a fixed number of elements from the start * * @stability stable * @category getters * @since 2.0.0 */ (self: Iterable, n: number): Array; }; /** * Removes the last `n` elements, creating a new array. * * **When to use** * * Use to remove the last `n` elements from an iterable. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`. * * **Example** (Dropping from the end) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dropRight([1, 2, 3, 4, 5], 2) // => [1, 2, 3] * ``` * * @see {@link drop} — remove from the start * @see {@link takeRight} — keep from the end * * @stability stable * @category getters * @since 2.0.0 */ export declare const dropRight: { /** * Removes the last `n` elements, creating a new array. * * **When to use** * * Use to remove the last `n` elements from an iterable. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`. * * **Example** (Dropping from the end) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dropRight([1, 2, 3, 4, 5], 2) // => [1, 2, 3] * ``` * * @see {@link drop} — remove from the start * @see {@link takeRight} — keep from the end * * @stability stable * @category getters * @since 2.0.0 */ (n: number): (self: Iterable) => Array; /** * Removes the last `n` elements, creating a new array. * * **When to use** * * Use to remove the last `n` elements from an iterable. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`. * * **Example** (Dropping from the end) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dropRight([1, 2, 3, 4, 5], 2) // => [1, 2, 3] * ``` * * @see {@link drop} — remove from the start * @see {@link takeRight} — keep from the end * * @stability stable * @category getters * @since 2.0.0 */ (self: Iterable, n: number): Array; }; /** * Drops elements from the start while the predicate holds, returning the rest. * * **When to use** * * Use to remove a leading prefix of elements that satisfy a predicate. * * **Details** * * The predicate receives `(element, index)`. * * **Example** (Dropping while condition holds) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dropWhile([1, 2, 3, 4, 5], (x) => x < 4) // => [4, 5] * ``` * * @see {@link takeWhile} — keep the matching prefix instead * @see {@link drop} — drop a fixed count * * @stability stable * @category getters * @since 2.0.0 */ export declare const dropWhile: { /** * Drops elements from the start while the predicate holds, returning the rest. * * **When to use** * * Use to remove a leading prefix of elements that satisfy a predicate. * * **Details** * * The predicate receives `(element, index)`. * * **Example** (Dropping while condition holds) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dropWhile([1, 2, 3, 4, 5], (x) => x < 4) // => [4, 5] * ``` * * @see {@link takeWhile} — keep the matching prefix instead * @see {@link drop} — drop a fixed count * * @stability stable * @category getters * @since 2.0.0 */ (predicate: (a: NoInfer, i: number) => boolean): (self: Iterable) => Array; /** * Drops elements from the start while the predicate holds, returning the rest. * * **When to use** * * Use to remove a leading prefix of elements that satisfy a predicate. * * **Details** * * The predicate receives `(element, index)`. * * **Example** (Dropping while condition holds) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dropWhile([1, 2, 3, 4, 5], (x) => x < 4) // => [4, 5] * ``` * * @see {@link takeWhile} — keep the matching prefix instead * @see {@link drop} — drop a fixed count * * @stability stable * @category getters * @since 2.0.0 */ (self: Iterable, predicate: (a: A, i: number) => boolean): Array; }; /** * Drops elements from the start while a `Filter` succeeds. * * **When to use** * * Use when you need to drop a prefix from an iterable by computing a `Result` * per element instead of using a simple boolean predicate. * * **Details** * * The filter receives `(element, index)`. The result contains the remaining * original elements after the first filter failure. * * @see {@link dropWhile} for dropping a prefix with a simple boolean predicate * @see {@link takeWhileFilter} for keeping only the matching prefix * * @stability stable * @category getters * @since 4.0.0 */ export declare const dropWhileFilter: { /** * Drops elements from the start while a `Filter` succeeds. * * **When to use** * * Use when you need to drop a prefix from an iterable by computing a `Result` * per element instead of using a simple boolean predicate. * * **Details** * * The filter receives `(element, index)`. The result contains the remaining * original elements after the first filter failure. * * @see {@link dropWhile} for dropping a prefix with a simple boolean predicate * @see {@link takeWhileFilter} for keeping only the matching prefix * * @stability stable * @category getters * @since 4.0.0 */ (f: (input: NoInfer, i: number) => Result.Result): (self: Iterable) => Array; /** * Drops elements from the start while a `Filter` succeeds. * * **When to use** * * Use when you need to drop a prefix from an iterable by computing a `Result` * per element instead of using a simple boolean predicate. * * **Details** * * The filter receives `(element, index)`. The result contains the remaining * original elements after the first filter failure. * * @see {@link dropWhile} for dropping a prefix with a simple boolean predicate * @see {@link takeWhileFilter} for keeping only the matching prefix * * @stability stable * @category getters * @since 4.0.0 */ (self: Iterable, f: (input: A, i: number) => Result.Result): Array; }; /** * Returns the index of the first element matching the predicate, wrapped in an * `Option`. * * **When to use** * * Use to find the index of the first matching element from the start of an * iterable. * * **Example** (Finding an index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirstIndex([5, 3, 8, 9], (x) => x > 5) // => Option.some(2) * ``` * * @see {@link findLastIndex} — search from the end * @see {@link findFirst} — get the element itself * * @stability stable * @category searching * @since 2.0.0 */ export declare const findFirstIndex: { /** * Returns the index of the first element matching the predicate, wrapped in an * `Option`. * * **When to use** * * Use to find the index of the first matching element from the start of an * iterable. * * **Example** (Finding an index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirstIndex([5, 3, 8, 9], (x) => x > 5) // => Option.some(2) * ``` * * @see {@link findLastIndex} — search from the end * @see {@link findFirst} — get the element itself * * @stability stable * @category searching * @since 2.0.0 */ (predicate: (a: NoInfer, i: number) => boolean): (self: Iterable) => Option.Option; /** * Returns the index of the first element matching the predicate, wrapped in an * `Option`. * * **When to use** * * Use to find the index of the first matching element from the start of an * iterable. * * **Example** (Finding an index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirstIndex([5, 3, 8, 9], (x) => x > 5) // => Option.some(2) * ``` * * @see {@link findLastIndex} — search from the end * @see {@link findFirst} — get the element itself * * @stability stable * @category searching * @since 2.0.0 */ (self: Iterable, predicate: (a: A, i: number) => boolean): Option.Option; }; /** * Returns the index of the last element matching the predicate, wrapped in an * `Option`. * * **When to use** * * Use to find the index of the last matching element from the end of an array. * * **Example** (Finding the last matching index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findLastIndex([1, 3, 8, 9], (x) => x < 5) // => Option.some(1) * ``` * * @see {@link findFirstIndex} — search from the start * @see {@link findLast} — get the element itself * * @stability stable * @category searching * @since 2.0.0 */ export declare const findLastIndex: { /** * Returns the index of the last element matching the predicate, wrapped in an * `Option`. * * **When to use** * * Use to find the index of the last matching element from the end of an array. * * **Example** (Finding the last matching index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findLastIndex([1, 3, 8, 9], (x) => x < 5) // => Option.some(1) * ``` * * @see {@link findFirstIndex} — search from the start * @see {@link findLast} — get the element itself * * @stability stable * @category searching * @since 2.0.0 */ (predicate: (a: NoInfer, i: number) => boolean): (self: Iterable) => Option.Option; /** * Returns the index of the last element matching the predicate, wrapped in an * `Option`. * * **When to use** * * Use to find the index of the last matching element from the end of an array. * * **Example** (Finding the last matching index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findLastIndex([1, 3, 8, 9], (x) => x < 5) // => Option.some(1) * ``` * * @see {@link findFirstIndex} — search from the start * @see {@link findLast} — get the element itself * * @stability stable * @category searching * @since 2.0.0 */ (self: Iterable, predicate: (a: A, i: number) => boolean): Option.Option; }; /** * Returns the first element matching a predicate, refinement, or mapping * function, wrapped in `Option`. * * **When to use** * * Use to scan an iterable in iteration order and return the first selected * element or mapped value as an `Option`. * * **Details** * * Accepts a predicate `(a, i) => boolean`, a refinement, or a function * `(a, i) => Option` for simultaneous find-and-transform. If no element * matches, this returns `Option.none()`. * * **Example** (Finding the first match) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirst([1, 2, 3, 4, 5], (x) => x > 3) // => Option.some(4) * ``` * * @see {@link findLast} — search from the end * @see {@link findFirstIndex} — get the index instead * @see {@link findFirstWithIndex} — get both element and index * * @stability stable * @category searching * @since 2.0.0 */ export declare const findFirst: { /** * Returns the first element matching a predicate, refinement, or mapping * function, wrapped in `Option`. * * **When to use** * * Use to scan an iterable in iteration order and return the first selected * element or mapped value as an `Option`. * * **Details** * * Accepts a predicate `(a, i) => boolean`, a refinement, or a function * `(a, i) => Option` for simultaneous find-and-transform. If no element * matches, this returns `Option.none()`. * * **Example** (Finding the first match) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirst([1, 2, 3, 4, 5], (x) => x > 3) // => Option.some(4) * ``` * * @see {@link findLast} — search from the end * @see {@link findFirstIndex} — get the index instead * @see {@link findFirstWithIndex} — get both element and index * * @stability stable * @category searching * @since 2.0.0 */ (f: (a: NoInfer, i: number) => Option.Option): (self: Iterable) => Option.Option; /** * Returns the first element matching a predicate, refinement, or mapping * function, wrapped in `Option`. * * **When to use** * * Use to scan an iterable in iteration order and return the first selected * element or mapped value as an `Option`. * * **Details** * * Accepts a predicate `(a, i) => boolean`, a refinement, or a function * `(a, i) => Option` for simultaneous find-and-transform. If no element * matches, this returns `Option.none()`. * * **Example** (Finding the first match) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirst([1, 2, 3, 4, 5], (x) => x > 3) // => Option.some(4) * ``` * * @see {@link findLast} — search from the end * @see {@link findFirstIndex} — get the index instead * @see {@link findFirstWithIndex} — get both element and index * * @stability stable * @category searching * @since 2.0.0 */ (refinement: (a: NoInfer, i: number) => a is B): (self: Iterable) => Option.Option; /** * Returns the first element matching a predicate, refinement, or mapping * function, wrapped in `Option`. * * **When to use** * * Use to scan an iterable in iteration order and return the first selected * element or mapped value as an `Option`. * * **Details** * * Accepts a predicate `(a, i) => boolean`, a refinement, or a function * `(a, i) => Option` for simultaneous find-and-transform. If no element * matches, this returns `Option.none()`. * * **Example** (Finding the first match) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirst([1, 2, 3, 4, 5], (x) => x > 3) // => Option.some(4) * ``` * * @see {@link findLast} — search from the end * @see {@link findFirstIndex} — get the index instead * @see {@link findFirstWithIndex} — get both element and index * * @stability stable * @category searching * @since 2.0.0 */ (predicate: (a: NoInfer, i: number) => boolean): (self: Iterable) => Option.Option; /** * Returns the first element matching a predicate, refinement, or mapping * function, wrapped in `Option`. * * **When to use** * * Use to scan an iterable in iteration order and return the first selected * element or mapped value as an `Option`. * * **Details** * * Accepts a predicate `(a, i) => boolean`, a refinement, or a function * `(a, i) => Option` for simultaneous find-and-transform. If no element * matches, this returns `Option.none()`. * * **Example** (Finding the first match) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirst([1, 2, 3, 4, 5], (x) => x > 3) // => Option.some(4) * ``` * * @see {@link findLast} — search from the end * @see {@link findFirstIndex} — get the index instead * @see {@link findFirstWithIndex} — get both element and index * * @stability stable * @category searching * @since 2.0.0 */ (self: Iterable, f: (a: A, i: number) => Option.Option): Option.Option; /** * Returns the first element matching a predicate, refinement, or mapping * function, wrapped in `Option`. * * **When to use** * * Use to scan an iterable in iteration order and return the first selected * element or mapped value as an `Option`. * * **Details** * * Accepts a predicate `(a, i) => boolean`, a refinement, or a function * `(a, i) => Option` for simultaneous find-and-transform. If no element * matches, this returns `Option.none()`. * * **Example** (Finding the first match) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirst([1, 2, 3, 4, 5], (x) => x > 3) // => Option.some(4) * ``` * * @see {@link findLast} — search from the end * @see {@link findFirstIndex} — get the index instead * @see {@link findFirstWithIndex} — get both element and index * * @stability stable * @category searching * @since 2.0.0 */ (self: Iterable, refinement: (a: A, i: number) => a is B): Option.Option; /** * Returns the first element matching a predicate, refinement, or mapping * function, wrapped in `Option`. * * **When to use** * * Use to scan an iterable in iteration order and return the first selected * element or mapped value as an `Option`. * * **Details** * * Accepts a predicate `(a, i) => boolean`, a refinement, or a function * `(a, i) => Option` for simultaneous find-and-transform. If no element * matches, this returns `Option.none()`. * * **Example** (Finding the first match) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirst([1, 2, 3, 4, 5], (x) => x > 3) // => Option.some(4) * ``` * * @see {@link findLast} — search from the end * @see {@link findFirstIndex} — get the index instead * @see {@link findFirstWithIndex} — get both element and index * * @stability stable * @category searching * @since 2.0.0 */ (self: Iterable, predicate: (a: A, i: number) => boolean): Option.Option; }; /** * Returns the first selected value together with its index, wrapped in an * `Option`. * * **When to use** * * Use to find both the first matching element and its index in one pass. * * **Details** * * Accepts a predicate, a refinement, or a function returning `Option`. For an * `Option`-returning function, returns `[mappedValue, index]` for the first * `Some`, or `Option.none()` if no element is selected. * * **Example** (Finding element with its index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirstWithIndex([1, 2, 3, 4, 5], (x) => x > 3) // => Option.some([4, 3]) * ``` * * @see {@link findFirst} — get only the element * @see {@link findFirstIndex} — get only the index * * @stability stable * @category searching * @since 3.17.0 */ export declare const findFirstWithIndex: { /** * Returns the first selected value together with its index, wrapped in an * `Option`. * * **When to use** * * Use to find both the first matching element and its index in one pass. * * **Details** * * Accepts a predicate, a refinement, or a function returning `Option`. For an * `Option`-returning function, returns `[mappedValue, index]` for the first * `Some`, or `Option.none()` if no element is selected. * * **Example** (Finding element with its index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirstWithIndex([1, 2, 3, 4, 5], (x) => x > 3) // => Option.some([4, 3]) * ``` * * @see {@link findFirst} — get only the element * @see {@link findFirstIndex} — get only the index * * @stability stable * @category searching * @since 3.17.0 */ (f: (a: NoInfer, i: number) => Option.Option): (self: Iterable) => Option.Option<[B, number]>; /** * Returns the first selected value together with its index, wrapped in an * `Option`. * * **When to use** * * Use to find both the first matching element and its index in one pass. * * **Details** * * Accepts a predicate, a refinement, or a function returning `Option`. For an * `Option`-returning function, returns `[mappedValue, index]` for the first * `Some`, or `Option.none()` if no element is selected. * * **Example** (Finding element with its index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirstWithIndex([1, 2, 3, 4, 5], (x) => x > 3) // => Option.some([4, 3]) * ``` * * @see {@link findFirst} — get only the element * @see {@link findFirstIndex} — get only the index * * @stability stable * @category searching * @since 3.17.0 */ (refinement: (a: NoInfer, i: number) => a is B): (self: Iterable) => Option.Option<[B, number]>; /** * Returns the first selected value together with its index, wrapped in an * `Option`. * * **When to use** * * Use to find both the first matching element and its index in one pass. * * **Details** * * Accepts a predicate, a refinement, or a function returning `Option`. For an * `Option`-returning function, returns `[mappedValue, index]` for the first * `Some`, or `Option.none()` if no element is selected. * * **Example** (Finding element with its index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirstWithIndex([1, 2, 3, 4, 5], (x) => x > 3) // => Option.some([4, 3]) * ``` * * @see {@link findFirst} — get only the element * @see {@link findFirstIndex} — get only the index * * @stability stable * @category searching * @since 3.17.0 */ (predicate: (a: NoInfer, i: number) => boolean): (self: Iterable) => Option.Option<[A, number]>; /** * Returns the first selected value together with its index, wrapped in an * `Option`. * * **When to use** * * Use to find both the first matching element and its index in one pass. * * **Details** * * Accepts a predicate, a refinement, or a function returning `Option`. For an * `Option`-returning function, returns `[mappedValue, index]` for the first * `Some`, or `Option.none()` if no element is selected. * * **Example** (Finding element with its index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirstWithIndex([1, 2, 3, 4, 5], (x) => x > 3) // => Option.some([4, 3]) * ``` * * @see {@link findFirst} — get only the element * @see {@link findFirstIndex} — get only the index * * @stability stable * @category searching * @since 3.17.0 */ (self: Iterable, f: (a: A, i: number) => Option.Option): Option.Option<[B, number]>; /** * Returns the first selected value together with its index, wrapped in an * `Option`. * * **When to use** * * Use to find both the first matching element and its index in one pass. * * **Details** * * Accepts a predicate, a refinement, or a function returning `Option`. For an * `Option`-returning function, returns `[mappedValue, index]` for the first * `Some`, or `Option.none()` if no element is selected. * * **Example** (Finding element with its index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirstWithIndex([1, 2, 3, 4, 5], (x) => x > 3) // => Option.some([4, 3]) * ``` * * @see {@link findFirst} — get only the element * @see {@link findFirstIndex} — get only the index * * @stability stable * @category searching * @since 3.17.0 */ (self: Iterable, refinement: (a: A, i: number) => a is B): Option.Option<[B, number]>; /** * Returns the first selected value together with its index, wrapped in an * `Option`. * * **When to use** * * Use to find both the first matching element and its index in one pass. * * **Details** * * Accepts a predicate, a refinement, or a function returning `Option`. For an * `Option`-returning function, returns `[mappedValue, index]` for the first * `Some`, or `Option.none()` if no element is selected. * * **Example** (Finding element with its index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findFirstWithIndex([1, 2, 3, 4, 5], (x) => x > 3) // => Option.some([4, 3]) * ``` * * @see {@link findFirst} — get only the element * @see {@link findFirstIndex} — get only the index * * @stability stable * @category searching * @since 3.17.0 */ (self: Iterable, predicate: (a: A, i: number) => boolean): Option.Option<[A, number]>; }; /** * Returns the last element matching a predicate, refinement, or mapping * function, wrapped in `Option`. * * **When to use** * * Use to find the last matching element from the end of an array. * * **Details** * * Searches from the end of the array. If no element matches, this returns * `Option.none()`. * * **Example** (Finding the last match) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findLast([1, 2, 3, 4, 5], (n) => n % 2 === 0) // => Option.some(4) * ``` * * @see {@link findFirst} — search from the start * @see {@link findLastIndex} — get the index instead * * @stability stable * @category searching * @since 2.0.0 */ export declare const findLast: { /** * Returns the last element matching a predicate, refinement, or mapping * function, wrapped in `Option`. * * **When to use** * * Use to find the last matching element from the end of an array. * * **Details** * * Searches from the end of the array. If no element matches, this returns * `Option.none()`. * * **Example** (Finding the last match) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findLast([1, 2, 3, 4, 5], (n) => n % 2 === 0) // => Option.some(4) * ``` * * @see {@link findFirst} — search from the start * @see {@link findLastIndex} — get the index instead * * @stability stable * @category searching * @since 2.0.0 */ (f: (a: NoInfer, i: number) => Option.Option): (self: Iterable) => Option.Option; /** * Returns the last element matching a predicate, refinement, or mapping * function, wrapped in `Option`. * * **When to use** * * Use to find the last matching element from the end of an array. * * **Details** * * Searches from the end of the array. If no element matches, this returns * `Option.none()`. * * **Example** (Finding the last match) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findLast([1, 2, 3, 4, 5], (n) => n % 2 === 0) // => Option.some(4) * ``` * * @see {@link findFirst} — search from the start * @see {@link findLastIndex} — get the index instead * * @stability stable * @category searching * @since 2.0.0 */ (refinement: (a: NoInfer, i: number) => a is B): (self: Iterable) => Option.Option; /** * Returns the last element matching a predicate, refinement, or mapping * function, wrapped in `Option`. * * **When to use** * * Use to find the last matching element from the end of an array. * * **Details** * * Searches from the end of the array. If no element matches, this returns * `Option.none()`. * * **Example** (Finding the last match) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findLast([1, 2, 3, 4, 5], (n) => n % 2 === 0) // => Option.some(4) * ``` * * @see {@link findFirst} — search from the start * @see {@link findLastIndex} — get the index instead * * @stability stable * @category searching * @since 2.0.0 */ (predicate: (a: NoInfer, i: number) => boolean): (self: Iterable) => Option.Option; /** * Returns the last element matching a predicate, refinement, or mapping * function, wrapped in `Option`. * * **When to use** * * Use to find the last matching element from the end of an array. * * **Details** * * Searches from the end of the array. If no element matches, this returns * `Option.none()`. * * **Example** (Finding the last match) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findLast([1, 2, 3, 4, 5], (n) => n % 2 === 0) // => Option.some(4) * ``` * * @see {@link findFirst} — search from the start * @see {@link findLastIndex} — get the index instead * * @stability stable * @category searching * @since 2.0.0 */ (self: Iterable, f: (a: A, i: number) => Option.Option): Option.Option; /** * Returns the last element matching a predicate, refinement, or mapping * function, wrapped in `Option`. * * **When to use** * * Use to find the last matching element from the end of an array. * * **Details** * * Searches from the end of the array. If no element matches, this returns * `Option.none()`. * * **Example** (Finding the last match) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findLast([1, 2, 3, 4, 5], (n) => n % 2 === 0) // => Option.some(4) * ``` * * @see {@link findFirst} — search from the start * @see {@link findLastIndex} — get the index instead * * @stability stable * @category searching * @since 2.0.0 */ (self: Iterable, refinement: (a: A, i: number) => a is B): Option.Option; /** * Returns the last element matching a predicate, refinement, or mapping * function, wrapped in `Option`. * * **When to use** * * Use to find the last matching element from the end of an array. * * **Details** * * Searches from the end of the array. If no element matches, this returns * `Option.none()`. * * **Example** (Finding the last match) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.findLast([1, 2, 3, 4, 5], (n) => n % 2 === 0) // => Option.some(4) * ``` * * @see {@link findFirst} — search from the start * @see {@link findLastIndex} — get the index instead * * @stability stable * @category searching * @since 2.0.0 */ (self: Iterable, predicate: (a: A, i: number) => boolean): Option.Option; }; /** * Inserts an element at the specified index safely, returning a new `NonEmptyArray` * wrapped in an `Option`. * * **When to use** * * Use to insert a single element at a specific position in an array. * * **Details** * * Valid indices are `0` to `length`, inclusive. Inserting at `length` appends. * * **Example** (Inserting at an index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.insertAt(["a", "b", "c", "e"], 3, "d") // => Option.some(["a", "b", "c", "d", "e"]) * ``` * * @see {@link replace} — replace an existing element * @see {@link modify} — transform an element at an index * * @stability stable * @category transforming * @since 2.0.0 */ export declare const insertAt: { /** * Inserts an element at the specified index safely, returning a new `NonEmptyArray` * wrapped in an `Option`. * * **When to use** * * Use to insert a single element at a specific position in an array. * * **Details** * * Valid indices are `0` to `length`, inclusive. Inserting at `length` appends. * * **Example** (Inserting at an index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.insertAt(["a", "b", "c", "e"], 3, "d") // => Option.some(["a", "b", "c", "d", "e"]) * ``` * * @see {@link replace} — replace an existing element * @see {@link modify} — transform an element at an index * * @stability stable * @category transforming * @since 2.0.0 */ (i: number, b: B): (self: Iterable) => Option.Option>; /** * Inserts an element at the specified index safely, returning a new `NonEmptyArray` * wrapped in an `Option`. * * **When to use** * * Use to insert a single element at a specific position in an array. * * **Details** * * Valid indices are `0` to `length`, inclusive. Inserting at `length` appends. * * **Example** (Inserting at an index) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.insertAt(["a", "b", "c", "e"], 3, "d") // => Option.some(["a", "b", "c", "d", "e"]) * ``` * * @see {@link replace} — replace an existing element * @see {@link modify} — transform an element at an index * * @stability stable * @category transforming * @since 2.0.0 */ (self: Iterable, i: number, b: B): Option.Option>; }; /** * Replaces the element at the specified index safely with a new value, returning the * updated array in `Option.some`. * * **When to use** * * Use to set a fixed replacement value at a specific index. * * **Details** * * Returns `Option.none()` when the index is out of bounds. * * **Example** (Replacing an element) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.replace([1, 2, 3], 1, 4) // => Option.some([1, 4, 3]) * ``` * * @see {@link modify} — transform an element with a function * @see {@link insertAt} — insert without removing * * @stability stable * @category transforming * @since 2.0.0 */ export declare const replace: { /** * Replaces the element at the specified index safely with a new value, returning the * updated array in `Option.some`. * * **When to use** * * Use to set a fixed replacement value at a specific index. * * **Details** * * Returns `Option.none()` when the index is out of bounds. * * **Example** (Replacing an element) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.replace([1, 2, 3], 1, 4) // => Option.some([1, 4, 3]) * ``` * * @see {@link modify} — transform an element with a function * @see {@link insertAt} — insert without removing * * @stability stable * @category transforming * @since 2.0.0 */ (i: number, b: B): = Iterable>(self: S) => Option.Option | B>>; /** * Replaces the element at the specified index safely with a new value, returning the * updated array in `Option.some`. * * **When to use** * * Use to set a fixed replacement value at a specific index. * * **Details** * * Returns `Option.none()` when the index is out of bounds. * * **Example** (Replacing an element) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.replace([1, 2, 3], 1, 4) // => Option.some([1, 4, 3]) * ``` * * @see {@link modify} — transform an element with a function * @see {@link insertAt} — insert without removing * * @stability stable * @category transforming * @since 2.0.0 */ = Iterable>(self: S, i: number, b: B): Option.Option | B>>; }; /** * Applies a function to the element at the specified index safely, returning the * updated array in `Option.some`. * * **When to use** * * Use to derive a replacement value from an array element at a specific index * while leaving the other elements unchanged. * * **Details** * * Returns `Option.none()` when the index is out of bounds. * * **Example** (Modifying an element) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * const values = [1, 2, 3, 4] * const double = (n: number) => n * 2 * * Array.modify(values, 2, double) // => Option.some([1, 2, 6, 4]) * Array.modify(values, 5, double) // => Option.none() * ``` * * @see {@link replace} — set a fixed value at an index * @see {@link modifyHeadNonEmpty} — modify the first element * @see {@link modifyLastNonEmpty} — modify the last element * * @stability stable * @category transforming * @since 2.0.0 */ export declare const modify: { /** * Applies a function to the element at the specified index safely, returning the * updated array in `Option.some`. * * **When to use** * * Use to derive a replacement value from an array element at a specific index * while leaving the other elements unchanged. * * **Details** * * Returns `Option.none()` when the index is out of bounds. * * **Example** (Modifying an element) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * const values = [1, 2, 3, 4] * const double = (n: number) => n * 2 * * Array.modify(values, 2, double) // => Option.some([1, 2, 6, 4]) * Array.modify(values, 5, double) // => Option.none() * ``` * * @see {@link replace} — set a fixed value at an index * @see {@link modifyHeadNonEmpty} — modify the first element * @see {@link modifyLastNonEmpty} — modify the last element * * @stability stable * @category transforming * @since 2.0.0 */ = Iterable>(i: number, f: (a: ReadonlyArray.Infer) => B): (self: S) => Option.Option | B>>; /** * Applies a function to the element at the specified index safely, returning the * updated array in `Option.some`. * * **When to use** * * Use to derive a replacement value from an array element at a specific index * while leaving the other elements unchanged. * * **Details** * * Returns `Option.none()` when the index is out of bounds. * * **Example** (Modifying an element) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * const values = [1, 2, 3, 4] * const double = (n: number) => n * 2 * * Array.modify(values, 2, double) // => Option.some([1, 2, 6, 4]) * Array.modify(values, 5, double) // => Option.none() * ``` * * @see {@link replace} — set a fixed value at an index * @see {@link modifyHeadNonEmpty} — modify the first element * @see {@link modifyLastNonEmpty} — modify the last element * * @stability stable * @category transforming * @since 2.0.0 */ = Iterable>(self: S, i: number, f: (a: ReadonlyArray.Infer) => B): Option.Option | B>>; }; /** * Removes the element at the specified index, returning a new array. If the * index is out of bounds, returns a copy of the original. * * **When to use** * * Use when you want a missing index to be a no-op and need a fresh array result * instead of an optional failure. * * **Example** (Removing an element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.remove([1, 2, 3, 4], 2) // => [1, 2, 4] * Array.remove([1, 2, 3, 4], 5) // => [1, 2, 3, 4] * ``` * * @see {@link insertAt} — insert an element * @see {@link filter} — remove elements by predicate * * @stability stable * @category transforming * @since 2.0.0 */ export declare const remove: { /** * Removes the element at the specified index, returning a new array. If the * index is out of bounds, returns a copy of the original. * * **When to use** * * Use when you want a missing index to be a no-op and need a fresh array result * instead of an optional failure. * * **Example** (Removing an element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.remove([1, 2, 3, 4], 2) // => [1, 2, 4] * Array.remove([1, 2, 3, 4], 5) // => [1, 2, 3, 4] * ``` * * @see {@link insertAt} — insert an element * @see {@link filter} — remove elements by predicate * * @stability stable * @category transforming * @since 2.0.0 */ (i: number): (self: Iterable) => Array; /** * Removes the element at the specified index, returning a new array. If the * index is out of bounds, returns a copy of the original. * * **When to use** * * Use when you want a missing index to be a no-op and need a fresh array result * instead of an optional failure. * * **Example** (Removing an element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.remove([1, 2, 3, 4], 2) // => [1, 2, 4] * Array.remove([1, 2, 3, 4], 5) // => [1, 2, 3, 4] * ``` * * @see {@link insertAt} — insert an element * @see {@link filter} — remove elements by predicate * * @stability stable * @category transforming * @since 2.0.0 */ (self: Iterable, i: number): Array; }; /** * Reverses an iterable into a new array. * * **When to use** * * Use to reverse an iterable into a new array without mutating the original * input. * * **Details** * * Preserves `NonEmptyArray` in the return type. * * **Example** (Reversing an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.reverse([1, 2, 3, 4]) // => [4, 3, 2, 1] * ``` * * @stability stable * @category transforming * @since 2.0.0 */ export declare const reverse: >(self: S) => S extends NonEmptyReadonlyArray ? NonEmptyArray : S extends Iterable ? Array : never; /** * Sorts an array by the given `Order`, returning a new array. * * **When to use** * * Use to sort an array using a single `Order` comparator. * * **Details** * * Preserves `NonEmptyArray` in the return type. Use `sortWith` to sort by a * derived key, or `sortBy` for multi-key sorting. * * **Example** (Sorting numbers) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * Array.sort([3, 1, 4, 1, 5], Order.Number) // => [1, 1, 3, 4, 5] * ``` * * @see {@link sortWith} — sort by a mapping function * @see {@link sortBy} — sort by multiple orders * * @stability stable * @category sorting * @since 2.0.0 */ export declare const sort: { /** * Sorts an array by the given `Order`, returning a new array. * * **When to use** * * Use to sort an array using a single `Order` comparator. * * **Details** * * Preserves `NonEmptyArray` in the return type. Use `sortWith` to sort by a * derived key, or `sortBy` for multi-key sorting. * * **Example** (Sorting numbers) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * Array.sort([3, 1, 4, 1, 5], Order.Number) // => [1, 1, 3, 4, 5] * ``` * * @see {@link sortWith} — sort by a mapping function * @see {@link sortBy} — sort by multiple orders * * @stability stable * @category sorting * @since 2.0.0 */ (O: Order.Order): >(self: S) => ReadonlyArray.With>; /** * Sorts an array by the given `Order`, returning a new array. * * **When to use** * * Use to sort an array using a single `Order` comparator. * * **Details** * * Preserves `NonEmptyArray` in the return type. Use `sortWith` to sort by a * derived key, or `sortBy` for multi-key sorting. * * **Example** (Sorting numbers) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * Array.sort([3, 1, 4, 1, 5], Order.Number) // => [1, 1, 3, 4, 5] * ``` * * @see {@link sortWith} — sort by a mapping function * @see {@link sortBy} — sort by multiple orders * * @stability stable * @category sorting * @since 2.0.0 */ (self: NonEmptyReadonlyArray, O: Order.Order): NonEmptyArray; /** * Sorts an array by the given `Order`, returning a new array. * * **When to use** * * Use to sort an array using a single `Order` comparator. * * **Details** * * Preserves `NonEmptyArray` in the return type. Use `sortWith` to sort by a * derived key, or `sortBy` for multi-key sorting. * * **Example** (Sorting numbers) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * Array.sort([3, 1, 4, 1, 5], Order.Number) // => [1, 1, 3, 4, 5] * ``` * * @see {@link sortWith} — sort by a mapping function * @see {@link sortBy} — sort by multiple orders * * @stability stable * @category sorting * @since 2.0.0 */ (self: Iterable, O: Order.Order): Array; }; /** * Sorts an array by a derived key using a mapping function and an `Order` for * that key. * * **When to use** * * Use when you need to sort values by a derived key, such as a string length or * object field, while keeping the original values. * * **Details** * * Equivalent to `sort(Order.mapInput(order, f))`, but more convenient. * * **Example** (Sorting strings by length) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * Array.sortWith(["aaa", "b", "cc"], (s) => s.length, Order.Number) // => ["b", "cc", "aaa"] * ``` * * @see {@link sort} for sorting with an `Order` that compares the elements directly * @see {@link sortBy} for sorting with multiple `Order`s applied in sequence * * @stability stable * @category sorting * @since 2.0.0 */ export declare const sortWith: { /** * Sorts an array by a derived key using a mapping function and an `Order` for * that key. * * **When to use** * * Use when you need to sort values by a derived key, such as a string length or * object field, while keeping the original values. * * **Details** * * Equivalent to `sort(Order.mapInput(order, f))`, but more convenient. * * **Example** (Sorting strings by length) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * Array.sortWith(["aaa", "b", "cc"], (s) => s.length, Order.Number) // => ["b", "cc", "aaa"] * ``` * * @see {@link sort} for sorting with an `Order` that compares the elements directly * @see {@link sortBy} for sorting with multiple `Order`s applied in sequence * * @stability stable * @category sorting * @since 2.0.0 */ , B>(f: (a: ReadonlyArray.Infer) => B, order: Order.Order): (self: S) => ReadonlyArray.With>; /** * Sorts an array by a derived key using a mapping function and an `Order` for * that key. * * **When to use** * * Use when you need to sort values by a derived key, such as a string length or * object field, while keeping the original values. * * **Details** * * Equivalent to `sort(Order.mapInput(order, f))`, but more convenient. * * **Example** (Sorting strings by length) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * Array.sortWith(["aaa", "b", "cc"], (s) => s.length, Order.Number) // => ["b", "cc", "aaa"] * ``` * * @see {@link sort} for sorting with an `Order` that compares the elements directly * @see {@link sortBy} for sorting with multiple `Order`s applied in sequence * * @stability stable * @category sorting * @since 2.0.0 */ (self: NonEmptyReadonlyArray, f: (a: A) => B, O: Order.Order): NonEmptyArray; /** * Sorts an array by a derived key using a mapping function and an `Order` for * that key. * * **When to use** * * Use when you need to sort values by a derived key, such as a string length or * object field, while keeping the original values. * * **Details** * * Equivalent to `sort(Order.mapInput(order, f))`, but more convenient. * * **Example** (Sorting strings by length) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * Array.sortWith(["aaa", "b", "cc"], (s) => s.length, Order.Number) // => ["b", "cc", "aaa"] * ``` * * @see {@link sort} for sorting with an `Order` that compares the elements directly * @see {@link sortBy} for sorting with multiple `Order`s applied in sequence * * @stability stable * @category sorting * @since 2.0.0 */ (self: Iterable, f: (a: A) => B, order: Order.Order): Array; }; /** * Sorts an array by multiple `Order`s applied in sequence: the first order is * used first; ties are broken by the second order, and so on. * * **When to use** * * Use to sort by multiple criteria where later orders break ties from earlier * ones. * * **Details** * * This is data-last only and returns a function. The return type preserves * `NonEmptyArray`. * * **Example** (Sorting by multiple keys) * * ```ts import.meta.vitest * import { Array, Order, pipe } from "effect" * * const users = [ * { name: "Alice", age: 30 }, * { name: "Bob", age: 25 }, * { name: "Charlie", age: 30 } * ] * * const sortedUsers = pipe( * users, * Array.sortBy( * Order.mapInput(Order.Number, (user: (typeof users)[number]) => user.age), * Order.mapInput(Order.String, (user: (typeof users)[number]) => user.name) * ) * ) * * sortedUsers.map((user) => user.name).join(",") // => "Bob,Alice,Charlie" * ``` * * @see {@link sort} — sort by a single `Order` * @see {@link sortWith} — sort by a derived key * * @stability stable * @category sorting * @since 2.0.0 */ export declare const sortBy: >(...orders: ReadonlyArray>>) => (self: S) => S extends NonEmptyReadonlyArray ? NonEmptyArray : S extends Iterable ? Array : never; /** * Pairs elements from two iterables by position. If the iterables differ in * length, the extra elements from the longer one are discarded. * * **When to use** * * Use when you need simple pairs of corresponding elements from two iterables. * * **Details** * * Returns `NonEmptyArray` when both inputs are non-empty. * * **Example** (Zipping two arrays) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.zip([1, 2, 3], ["a", "b"]) // => [[1, "a"], [2, "b"]] * ``` * * @see {@link zipWith} — zip with a combiner function * @see {@link unzip} — inverse operation * * @stability stable * @category zipping * @since 2.0.0 */ export declare const zip: { /** * Pairs elements from two iterables by position. If the iterables differ in * length, the extra elements from the longer one are discarded. * * **When to use** * * Use when you need simple pairs of corresponding elements from two iterables. * * **Details** * * Returns `NonEmptyArray` when both inputs are non-empty. * * **Example** (Zipping two arrays) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.zip([1, 2, 3], ["a", "b"]) // => [[1, "a"], [2, "b"]] * ``` * * @see {@link zipWith} — zip with a combiner function * @see {@link unzip} — inverse operation * * @stability stable * @category zipping * @since 2.0.0 */ (that: NonEmptyReadonlyArray): (self: NonEmptyReadonlyArray) => NonEmptyArray<[A, B]>; /** * Pairs elements from two iterables by position. If the iterables differ in * length, the extra elements from the longer one are discarded. * * **When to use** * * Use when you need simple pairs of corresponding elements from two iterables. * * **Details** * * Returns `NonEmptyArray` when both inputs are non-empty. * * **Example** (Zipping two arrays) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.zip([1, 2, 3], ["a", "b"]) // => [[1, "a"], [2, "b"]] * ``` * * @see {@link zipWith} — zip with a combiner function * @see {@link unzip} — inverse operation * * @stability stable * @category zipping * @since 2.0.0 */ (that: Iterable): (self: Iterable) => Array<[A, B]>; /** * Pairs elements from two iterables by position. If the iterables differ in * length, the extra elements from the longer one are discarded. * * **When to use** * * Use when you need simple pairs of corresponding elements from two iterables. * * **Details** * * Returns `NonEmptyArray` when both inputs are non-empty. * * **Example** (Zipping two arrays) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.zip([1, 2, 3], ["a", "b"]) // => [[1, "a"], [2, "b"]] * ``` * * @see {@link zipWith} — zip with a combiner function * @see {@link unzip} — inverse operation * * @stability stable * @category zipping * @since 2.0.0 */ (self: NonEmptyReadonlyArray, that: NonEmptyReadonlyArray): NonEmptyArray<[A, B]>; /** * Pairs elements from two iterables by position. If the iterables differ in * length, the extra elements from the longer one are discarded. * * **When to use** * * Use when you need simple pairs of corresponding elements from two iterables. * * **Details** * * Returns `NonEmptyArray` when both inputs are non-empty. * * **Example** (Zipping two arrays) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.zip([1, 2, 3], ["a", "b"]) // => [[1, "a"], [2, "b"]] * ``` * * @see {@link zipWith} — zip with a combiner function * @see {@link unzip} — inverse operation * * @stability stable * @category zipping * @since 2.0.0 */ (self: Iterable, that: Iterable): Array<[A, B]>; }; /** * Combines elements from two iterables pairwise using a function. If the * iterables differ in length, extra elements are discarded. * * **When to use** * * Use when zipping two iterables in an array pipeline and each pair should * become a computed array element instead of a tuple. * * **Example** (Zipping with addition) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b) // => [5, 7, 9] * ``` * * @see {@link zip} — zip into tuples * * @stability stable * @category zipping * @since 2.0.0 */ export declare const zipWith: { /** * Combines elements from two iterables pairwise using a function. If the * iterables differ in length, extra elements are discarded. * * **When to use** * * Use when zipping two iterables in an array pipeline and each pair should * become a computed array element instead of a tuple. * * **Example** (Zipping with addition) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b) // => [5, 7, 9] * ``` * * @see {@link zip} — zip into tuples * * @stability stable * @category zipping * @since 2.0.0 */ (that: NonEmptyReadonlyArray, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray) => NonEmptyArray; /** * Combines elements from two iterables pairwise using a function. If the * iterables differ in length, extra elements are discarded. * * **When to use** * * Use when zipping two iterables in an array pipeline and each pair should * become a computed array element instead of a tuple. * * **Example** (Zipping with addition) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b) // => [5, 7, 9] * ``` * * @see {@link zip} — zip into tuples * * @stability stable * @category zipping * @since 2.0.0 */ (that: Iterable, f: (a: A, b: B) => C): (self: Iterable) => Array; /** * Combines elements from two iterables pairwise using a function. If the * iterables differ in length, extra elements are discarded. * * **When to use** * * Use when zipping two iterables in an array pipeline and each pair should * become a computed array element instead of a tuple. * * **Example** (Zipping with addition) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b) // => [5, 7, 9] * ``` * * @see {@link zip} — zip into tuples * * @stability stable * @category zipping * @since 2.0.0 */ (self: NonEmptyReadonlyArray, that: NonEmptyReadonlyArray, f: (a: A, b: B) => C): NonEmptyArray; /** * Combines elements from two iterables pairwise using a function. If the * iterables differ in length, extra elements are discarded. * * **When to use** * * Use when zipping two iterables in an array pipeline and each pair should * become a computed array element instead of a tuple. * * **Example** (Zipping with addition) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b) // => [5, 7, 9] * ``` * * @see {@link zip} — zip into tuples * * @stability stable * @category zipping * @since 2.0.0 */ (self: Iterable, that: Iterable, f: (a: A, b: B) => C): Array; }; /** * Splits an array of pairs into two arrays. Inverse of {@link zip}. * * **Example** (Unzipping pairs) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.unzip([[1, "a"], [2, "b"], [3, "c"]]) // => [[1, 2, 3], ["a", "b", "c"]] * ``` * * @see {@link zip} — combine two arrays into pairs * * @stability stable * @category zipping * @since 2.0.0 */ export declare const unzip: >(self: S) => S extends NonEmptyReadonlyArray ? [NonEmptyArray, NonEmptyArray] : S extends Iterable ? [Array, Array] : never; /** * Places a separator element between every pair of elements. * * **When to use** * * Use to insert a separator between elements, for example when preparing data for display or concatenation. * * **Details** * * The return type preserves `NonEmptyArray`. Empty inputs produce an empty * result. * * **Example** (Interspersing a separator) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.intersperse([1, 2, 3], 0) // => [1, 0, 2, 0, 3] * ``` * * @see {@link join} — intersperse and join into a string * * @stability stable * @category transforming * @since 2.0.0 */ export declare const intersperse: { /** * Places a separator element between every pair of elements. * * **When to use** * * Use to insert a separator between elements, for example when preparing data for display or concatenation. * * **Details** * * The return type preserves `NonEmptyArray`. Empty inputs produce an empty * result. * * **Example** (Interspersing a separator) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.intersperse([1, 2, 3], 0) // => [1, 0, 2, 0, 3] * ``` * * @see {@link join} — intersperse and join into a string * * @stability stable * @category transforming * @since 2.0.0 */ (middle: B): >(self: S) => ReadonlyArray.With | B>; /** * Places a separator element between every pair of elements. * * **When to use** * * Use to insert a separator between elements, for example when preparing data for display or concatenation. * * **Details** * * The return type preserves `NonEmptyArray`. Empty inputs produce an empty * result. * * **Example** (Interspersing a separator) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.intersperse([1, 2, 3], 0) // => [1, 0, 2, 0, 3] * ``` * * @see {@link join} — intersperse and join into a string * * @stability stable * @category transforming * @since 2.0.0 */ (self: NonEmptyReadonlyArray, middle: B): NonEmptyArray; /** * Places a separator element between every pair of elements. * * **When to use** * * Use to insert a separator between elements, for example when preparing data for display or concatenation. * * **Details** * * The return type preserves `NonEmptyArray`. Empty inputs produce an empty * result. * * **Example** (Interspersing a separator) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.intersperse([1, 2, 3], 0) // => [1, 0, 2, 0, 3] * ``` * * @see {@link join} — intersperse and join into a string * * @stability stable * @category transforming * @since 2.0.0 */ (self: Iterable, middle: B): Array; }; /** * Applies a function to the first element of a non-empty array, returning a * new array. * * **When to use** * * Use to transform the first element of a non-empty array while preserving the rest. * * **Example** (Modifying the head) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.modifyHeadNonEmpty([1, 2, 3], (n) => n * 10) // => [10, 2, 3] * ``` * * @see {@link setHeadNonEmpty} — replace with a fixed value * @see {@link modifyLastNonEmpty} — modify the last element * * @stability stable * @category transforming * @since 4.0.0 */ export declare const modifyHeadNonEmpty: { /** * Applies a function to the first element of a non-empty array, returning a * new array. * * **When to use** * * Use to transform the first element of a non-empty array while preserving the rest. * * **Example** (Modifying the head) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.modifyHeadNonEmpty([1, 2, 3], (n) => n * 10) // => [10, 2, 3] * ``` * * @see {@link setHeadNonEmpty} — replace with a fixed value * @see {@link modifyLastNonEmpty} — modify the last element * * @stability stable * @category transforming * @since 4.0.0 */ (f: (a: A) => B): (self: NonEmptyReadonlyArray) => NonEmptyArray; /** * Applies a function to the first element of a non-empty array, returning a * new array. * * **When to use** * * Use to transform the first element of a non-empty array while preserving the rest. * * **Example** (Modifying the head) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.modifyHeadNonEmpty([1, 2, 3], (n) => n * 10) // => [10, 2, 3] * ``` * * @see {@link setHeadNonEmpty} — replace with a fixed value * @see {@link modifyLastNonEmpty} — modify the last element * * @stability stable * @category transforming * @since 4.0.0 */ (self: NonEmptyReadonlyArray, f: (a: A) => B): NonEmptyArray; }; /** * Replaces the first element of a non-empty array with a new value. * * **When to use** * * Use when you already know the array is non-empty and the replacement value * does not depend on the current first element. * * **Example** (Setting the head) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.setHeadNonEmpty([1, 2, 3], 10) // => [10, 2, 3] * ``` * * @see {@link modifyHeadNonEmpty} — transform the head with a function * @see {@link setLastNonEmpty} — replace the last element * * @stability stable * @category transforming * @since 4.0.0 */ export declare const setHeadNonEmpty: { /** * Replaces the first element of a non-empty array with a new value. * * **When to use** * * Use when you already know the array is non-empty and the replacement value * does not depend on the current first element. * * **Example** (Setting the head) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.setHeadNonEmpty([1, 2, 3], 10) // => [10, 2, 3] * ``` * * @see {@link modifyHeadNonEmpty} — transform the head with a function * @see {@link setLastNonEmpty} — replace the last element * * @stability stable * @category transforming * @since 4.0.0 */ (b: B): (self: NonEmptyReadonlyArray) => NonEmptyArray; /** * Replaces the first element of a non-empty array with a new value. * * **When to use** * * Use when you already know the array is non-empty and the replacement value * does not depend on the current first element. * * **Example** (Setting the head) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.setHeadNonEmpty([1, 2, 3], 10) // => [10, 2, 3] * ``` * * @see {@link modifyHeadNonEmpty} — transform the head with a function * @see {@link setLastNonEmpty} — replace the last element * * @stability stable * @category transforming * @since 4.0.0 */ (self: NonEmptyReadonlyArray, b: B): NonEmptyArray; }; /** * Applies a function to the last element of a non-empty array, returning a * new array. * * **When to use** * * Use when you already know the array is non-empty and the new last element * depends on the current last element. * * **Example** (Modifying the last element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.modifyLastNonEmpty([1, 2, 3], (n) => n * 2) // => [1, 2, 6] * ``` * * @see {@link setLastNonEmpty} — replace with a fixed value * @see {@link modifyHeadNonEmpty} — modify the first element * * @stability stable * @category transforming * @since 4.0.0 */ export declare const modifyLastNonEmpty: { /** * Applies a function to the last element of a non-empty array, returning a * new array. * * **When to use** * * Use when you already know the array is non-empty and the new last element * depends on the current last element. * * **Example** (Modifying the last element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.modifyLastNonEmpty([1, 2, 3], (n) => n * 2) // => [1, 2, 6] * ``` * * @see {@link setLastNonEmpty} — replace with a fixed value * @see {@link modifyHeadNonEmpty} — modify the first element * * @stability stable * @category transforming * @since 4.0.0 */ (f: (a: A) => B): (self: NonEmptyReadonlyArray) => NonEmptyArray; /** * Applies a function to the last element of a non-empty array, returning a * new array. * * **When to use** * * Use when you already know the array is non-empty and the new last element * depends on the current last element. * * **Example** (Modifying the last element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.modifyLastNonEmpty([1, 2, 3], (n) => n * 2) // => [1, 2, 6] * ``` * * @see {@link setLastNonEmpty} — replace with a fixed value * @see {@link modifyHeadNonEmpty} — modify the first element * * @stability stable * @category transforming * @since 4.0.0 */ (self: NonEmptyReadonlyArray, f: (a: A) => B): NonEmptyArray; }; /** * Replaces the last element of a non-empty array with a new value. * * **When to use** * * Use when you already know the array is non-empty and the replacement value * does not depend on the current last element. * * **Example** (Setting the last element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.setLastNonEmpty([1, 2, 3], 4) // => [1, 2, 4] * ``` * * @see {@link modifyLastNonEmpty} — transform the last element with a function * @see {@link setHeadNonEmpty} — replace the first element * * @stability stable * @category transforming * @since 4.0.0 */ export declare const setLastNonEmpty: { /** * Replaces the last element of a non-empty array with a new value. * * **When to use** * * Use when you already know the array is non-empty and the replacement value * does not depend on the current last element. * * **Example** (Setting the last element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.setLastNonEmpty([1, 2, 3], 4) // => [1, 2, 4] * ``` * * @see {@link modifyLastNonEmpty} — transform the last element with a function * @see {@link setHeadNonEmpty} — replace the first element * * @stability stable * @category transforming * @since 4.0.0 */ (b: B): (self: NonEmptyReadonlyArray) => NonEmptyArray; /** * Replaces the last element of a non-empty array with a new value. * * **When to use** * * Use when you already know the array is non-empty and the replacement value * does not depend on the current last element. * * **Example** (Setting the last element) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.setLastNonEmpty([1, 2, 3], 4) // => [1, 2, 4] * ``` * * @see {@link modifyLastNonEmpty} — transform the last element with a function * @see {@link setHeadNonEmpty} — replace the first element * * @stability stable * @category transforming * @since 4.0.0 */ (self: NonEmptyReadonlyArray, b: B): NonEmptyArray; }; /** * Transforms an array by rotating it `n` steps. Positive `n` rotates right; negative `n` * rotates left. * * **When to use** * * Use when elements should wrap around the end of the array rather than being * dropped. * * **Details** * * `n` is rounded to the nearest integer before rotating. The return type * preserves `NonEmptyArray`. Empty arrays, or rotations normalized to `0`, * return a copy. * * **Example** (Rotating elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.rotate(["a", "b", "c", "d"], 2) // => ["c", "d", "a", "b"] * ``` * * @see {@link take} for taking a fixed number of elements from the start * @see {@link drop} for dropping a fixed number of elements from the start * * @stability stable * @category transforming * @since 2.0.0 */ export declare const rotate: { /** * Transforms an array by rotating it `n` steps. Positive `n` rotates right; negative `n` * rotates left. * * **When to use** * * Use when elements should wrap around the end of the array rather than being * dropped. * * **Details** * * `n` is rounded to the nearest integer before rotating. The return type * preserves `NonEmptyArray`. Empty arrays, or rotations normalized to `0`, * return a copy. * * **Example** (Rotating elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.rotate(["a", "b", "c", "d"], 2) // => ["c", "d", "a", "b"] * ``` * * @see {@link take} for taking a fixed number of elements from the start * @see {@link drop} for dropping a fixed number of elements from the start * * @stability stable * @category transforming * @since 2.0.0 */ (n: number): >(self: S) => ReadonlyArray.With>; /** * Transforms an array by rotating it `n` steps. Positive `n` rotates right; negative `n` * rotates left. * * **When to use** * * Use when elements should wrap around the end of the array rather than being * dropped. * * **Details** * * `n` is rounded to the nearest integer before rotating. The return type * preserves `NonEmptyArray`. Empty arrays, or rotations normalized to `0`, * return a copy. * * **Example** (Rotating elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.rotate(["a", "b", "c", "d"], 2) // => ["c", "d", "a", "b"] * ``` * * @see {@link take} for taking a fixed number of elements from the start * @see {@link drop} for dropping a fixed number of elements from the start * * @stability stable * @category transforming * @since 2.0.0 */ (self: NonEmptyReadonlyArray, n: number): NonEmptyArray; /** * Transforms an array by rotating it `n` steps. Positive `n` rotates right; negative `n` * rotates left. * * **When to use** * * Use when elements should wrap around the end of the array rather than being * dropped. * * **Details** * * `n` is rounded to the nearest integer before rotating. The return type * preserves `NonEmptyArray`. Empty arrays, or rotations normalized to `0`, * return a copy. * * **Example** (Rotating elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.rotate(["a", "b", "c", "d"], 2) // => ["c", "d", "a", "b"] * ``` * * @see {@link take} for taking a fixed number of elements from the start * @see {@link drop} for dropping a fixed number of elements from the start * * @stability stable * @category transforming * @since 2.0.0 */ (self: Iterable, n: number): Array; }; /** * Returns a membership-test function using a custom equivalence. * * **When to use** * * Use when checking membership with caller-provided equality instead of * `Equal.asEquivalence()`. * * **Example** (Checking with custom equality) * * ```ts import.meta.vitest * import { Array, pipe } from "effect" * * const containsNumber = Array.containsWith((a: number, b: number) => a === b) * * pipe([1, 2, 3, 4], containsNumber(3)) // => true * ``` * * @see {@link contains} for the `Equal.asEquivalence()` variant * * @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 array contains a value, using `Equal.asEquivalence()` for * comparison. * * **When to use** * * Use to check whether an iterable contains a value using Effect's default * equality instead of providing a comparison function. * * **Example** (Checking membership) * * ```ts import.meta.vitest * import { Array, pipe } from "effect" * * pipe(["a", "b", "c", "d"], Array.contains("c")) // => true * ``` * * @see {@link containsWith} — use custom equality * * @stability stable * @category predicates * @since 2.0.0 */ export declare const contains: { /** * Checks whether an array contains a value, using `Equal.asEquivalence()` for * comparison. * * **When to use** * * Use to check whether an iterable contains a value using Effect's default * equality instead of providing a comparison function. * * **Example** (Checking membership) * * ```ts import.meta.vitest * import { Array, pipe } from "effect" * * pipe(["a", "b", "c", "d"], Array.contains("c")) // => true * ``` * * @see {@link containsWith} — use custom equality * * @stability stable * @category predicates * @since 2.0.0 */ (a: A): (self: Iterable) => boolean; /** * Checks whether an array contains a value, using `Equal.asEquivalence()` for * comparison. * * **When to use** * * Use to check whether an iterable contains a value using Effect's default * equality instead of providing a comparison function. * * **Example** (Checking membership) * * ```ts import.meta.vitest * import { Array, pipe } from "effect" * * pipe(["a", "b", "c", "d"], Array.contains("c")) // => true * ``` * * @see {@link containsWith} — use custom equality * * @stability stable * @category predicates * @since 2.0.0 */ (self: Iterable, a: A): boolean; }; /** * Applies a function repeatedly to consume prefixes of the array and collect * the values it produces. * * **When to use** * * Use when you need custom grouping logic where each step returns both a value * and the remaining input. * * **Details** * * The function receives a `NonEmptyReadonlyArray` and returns `[value, rest]`. * Processing continues until the remaining array is empty. * * **Example** (Chopping an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.chop([1, 2, 3, 4, 5], (as): [number, Array] => [as[0] * 2, as.slice(1)]) // => [2, 4, 6, 8, 10] * ``` * * @see {@link chunksOf} — split into fixed-size chunks * @see {@link splitAt} — split at an index * * @stability stable * @category splitting * @since 2.0.0 */ export declare const chop: { /** * Applies a function repeatedly to consume prefixes of the array and collect * the values it produces. * * **When to use** * * Use when you need custom grouping logic where each step returns both a value * and the remaining input. * * **Details** * * The function receives a `NonEmptyReadonlyArray` and returns `[value, rest]`. * Processing continues until the remaining array is empty. * * **Example** (Chopping an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.chop([1, 2, 3, 4, 5], (as): [number, Array] => [as[0] * 2, as.slice(1)]) // => [2, 4, 6, 8, 10] * ``` * * @see {@link chunksOf} — split into fixed-size chunks * @see {@link splitAt} — split at an index * * @stability stable * @category splitting * @since 2.0.0 */ , B>(f: (as: NonEmptyReadonlyArray>) => readonly [B, ReadonlyArray>]): (self: S) => ReadonlyArray.With>; /** * Applies a function repeatedly to consume prefixes of the array and collect * the values it produces. * * **When to use** * * Use when you need custom grouping logic where each step returns both a value * and the remaining input. * * **Details** * * The function receives a `NonEmptyReadonlyArray` and returns `[value, rest]`. * Processing continues until the remaining array is empty. * * **Example** (Chopping an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.chop([1, 2, 3, 4, 5], (as): [number, Array] => [as[0] * 2, as.slice(1)]) // => [2, 4, 6, 8, 10] * ``` * * @see {@link chunksOf} — split into fixed-size chunks * @see {@link splitAt} — split at an index * * @stability stable * @category splitting * @since 2.0.0 */ (self: NonEmptyReadonlyArray, f: (as: NonEmptyReadonlyArray) => readonly [B, ReadonlyArray]): NonEmptyArray; /** * Applies a function repeatedly to consume prefixes of the array and collect * the values it produces. * * **When to use** * * Use when you need custom grouping logic where each step returns both a value * and the remaining input. * * **Details** * * The function receives a `NonEmptyReadonlyArray` and returns `[value, rest]`. * Processing continues until the remaining array is empty. * * **Example** (Chopping an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.chop([1, 2, 3, 4, 5], (as): [number, Array] => [as[0] * 2, as.slice(1)]) // => [2, 4, 6, 8, 10] * ``` * * @see {@link chunksOf} — split into fixed-size chunks * @see {@link splitAt} — split at an index * * @stability stable * @category splitting * @since 2.0.0 */ (self: Iterable, f: (as: NonEmptyReadonlyArray) => readonly [B, ReadonlyArray]): Array; }; /** * Splits an iterable into two arrays at the given index. * * **When to use** * * Use to divide an array into a prefix and suffix at a specific position. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`, * which places all elements in the second array. * * **Example** (Splitting at an index) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.splitAt([1, 2, 3, 4, 5], 3) // => [[1, 2, 3], [4, 5]] * ``` * * @see {@link splitAtNonEmpty} — for non-empty arrays * @see {@link splitWhere} — split at a predicate boundary * * @stability stable * @category splitting * @since 2.0.0 */ export declare const splitAt: { /** * Splits an iterable into two arrays at the given index. * * **When to use** * * Use to divide an array into a prefix and suffix at a specific position. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`, * which places all elements in the second array. * * **Example** (Splitting at an index) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.splitAt([1, 2, 3, 4, 5], 3) // => [[1, 2, 3], [4, 5]] * ``` * * @see {@link splitAtNonEmpty} — for non-empty arrays * @see {@link splitWhere} — split at a predicate boundary * * @stability stable * @category splitting * @since 2.0.0 */ (n: number): (self: Iterable) => [beforeIndex: Array, fromIndex: Array]; /** * Splits an iterable into two arrays at the given index. * * **When to use** * * Use to divide an array into a prefix and suffix at a specific position. * * **Details** * * `n` is rounded down and clamped to `[0, length]`. `NaN` is treated as `0`, * which places all elements in the second array. * * **Example** (Splitting at an index) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.splitAt([1, 2, 3, 4, 5], 3) // => [[1, 2, 3], [4, 5]] * ``` * * @see {@link splitAtNonEmpty} — for non-empty arrays * @see {@link splitWhere} — split at a predicate boundary * * @stability stable * @category splitting * @since 2.0.0 */ (self: Iterable, n: number): [beforeIndex: Array, fromIndex: Array]; }; /** * Splits a non-empty array into two parts at the given index. The first part * is guaranteed to be non-empty (`n` is clamped to >= 1). * * **When to use** * * Use when downstream code requires the left side of the split to contain at * least one element. * * **Details** * * `n` is rounded down and clamped to `[1, length]`. `NaN` is treated as `1`. * * **Example** (Splitting a non-empty array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.splitAtNonEmpty(["a", "b", "c", "d", "e"], 3) // => [["a", "b", "c"], ["d", "e"]] * ``` * * @see {@link splitAt} — for possibly-empty arrays * * @stability stable * @category splitting * @since 4.0.0 */ export declare const splitAtNonEmpty: { /** * Splits a non-empty array into two parts at the given index. The first part * is guaranteed to be non-empty (`n` is clamped to >= 1). * * **When to use** * * Use when downstream code requires the left side of the split to contain at * least one element. * * **Details** * * `n` is rounded down and clamped to `[1, length]`. `NaN` is treated as `1`. * * **Example** (Splitting a non-empty array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.splitAtNonEmpty(["a", "b", "c", "d", "e"], 3) // => [["a", "b", "c"], ["d", "e"]] * ``` * * @see {@link splitAt} — for possibly-empty arrays * * @stability stable * @category splitting * @since 4.0.0 */ (n: number): (self: NonEmptyReadonlyArray) => [beforeIndex: NonEmptyArray, fromIndex: Array]; /** * Splits a non-empty array into two parts at the given index. The first part * is guaranteed to be non-empty (`n` is clamped to >= 1). * * **When to use** * * Use when downstream code requires the left side of the split to contain at * least one element. * * **Details** * * `n` is rounded down and clamped to `[1, length]`. `NaN` is treated as `1`. * * **Example** (Splitting a non-empty array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.splitAtNonEmpty(["a", "b", "c", "d", "e"], 3) // => [["a", "b", "c"], ["d", "e"]] * ``` * * @see {@link splitAt} — for possibly-empty arrays * * @stability stable * @category splitting * @since 4.0.0 */ (self: NonEmptyReadonlyArray, n: number): [beforeIndex: NonEmptyArray, fromIndex: Array]; }; /** * Splits an iterable into `n` roughly equal-sized chunks. * * **When to use** * * Use to distribute elements across a fixed number of groups, such as when splitting work across threads. * * **Details** * * `n` is rounded down and normalized to at least `1`, with `NaN` treated as * `1`. The last chunk may be shorter. * * **Example** (Splitting into groups) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.split([1, 2, 3, 4, 5, 6, 7, 8], 3) // => [[1, 2, 3], [4, 5, 6], [7, 8]] * ``` * * @see {@link chunksOf} — split into fixed-size chunks * * @stability stable * @category splitting * @since 2.0.0 */ export declare const split: { /** * Splits an iterable into `n` roughly equal-sized chunks. * * **When to use** * * Use to distribute elements across a fixed number of groups, such as when splitting work across threads. * * **Details** * * `n` is rounded down and normalized to at least `1`, with `NaN` treated as * `1`. The last chunk may be shorter. * * **Example** (Splitting into groups) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.split([1, 2, 3, 4, 5, 6, 7, 8], 3) // => [[1, 2, 3], [4, 5, 6], [7, 8]] * ``` * * @see {@link chunksOf} — split into fixed-size chunks * * @stability stable * @category splitting * @since 2.0.0 */ (n: number): (self: Iterable) => Array>; /** * Splits an iterable into `n` roughly equal-sized chunks. * * **When to use** * * Use to distribute elements across a fixed number of groups, such as when splitting work across threads. * * **Details** * * `n` is rounded down and normalized to at least `1`, with `NaN` treated as * `1`. The last chunk may be shorter. * * **Example** (Splitting into groups) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.split([1, 2, 3, 4, 5, 6, 7, 8], 3) // => [[1, 2, 3], [4, 5, 6], [7, 8]] * ``` * * @see {@link chunksOf} — split into fixed-size chunks * * @stability stable * @category splitting * @since 2.0.0 */ (self: Iterable, n: number): Array>; }; /** * Splits an iterable at the first element matching the predicate. The matching * element is included in the second array. * * **When to use** * * Use when you need to split an array at the first element that marks a * condition boundary. * * **Example** (Splitting at a condition) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.splitWhere([1, 2, 3, 4, 5], (n) => n > 3) // => [[1, 2, 3], [4, 5]] * ``` * * @see {@link span} — splits at the first element that fails the predicate * @see {@link splitAt} — split at a fixed index * * @stability stable * @category splitting * @since 2.0.0 */ export declare const splitWhere: { /** * Splits an iterable at the first element matching the predicate. The matching * element is included in the second array. * * **When to use** * * Use when you need to split an array at the first element that marks a * condition boundary. * * **Example** (Splitting at a condition) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.splitWhere([1, 2, 3, 4, 5], (n) => n > 3) // => [[1, 2, 3], [4, 5]] * ``` * * @see {@link span} — splits at the first element that fails the predicate * @see {@link splitAt} — split at a fixed index * * @stability stable * @category splitting * @since 2.0.0 */ (predicate: (a: NoInfer, i: number) => boolean): (self: Iterable) => [beforeMatch: Array, fromMatch: Array]; /** * Splits an iterable at the first element matching the predicate. The matching * element is included in the second array. * * **When to use** * * Use when you need to split an array at the first element that marks a * condition boundary. * * **Example** (Splitting at a condition) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.splitWhere([1, 2, 3, 4, 5], (n) => n > 3) // => [[1, 2, 3], [4, 5]] * ``` * * @see {@link span} — splits at the first element that fails the predicate * @see {@link splitAt} — split at a fixed index * * @stability stable * @category splitting * @since 2.0.0 */ (self: Iterable, predicate: (a: A, i: number) => boolean): [beforeMatch: Array, fromMatch: Array]; }; /** * Creates a shallow copy of an array. * * **When to use** * * Use to create a distinct array reference for an existing array, for example * before mutating the returned array. * * **Details** * * The return type preserves `NonEmptyArray`. Use this when you need a distinct * reference, for example before mutating the returned array. * * **Example** (Copying an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * const original = [1, 2, 3] * const copied = Array.copy(original) * * copied // => [1, 2, 3] * original === copied // => false * ``` * * @see {@link fromIterable} — returns the same reference for arrays * * @stability stable * @category transforming * @since 2.0.0 */ export declare const copy: { /** * Creates a shallow copy of an array. * * **When to use** * * Use to create a distinct array reference for an existing array, for example * before mutating the returned array. * * **Details** * * The return type preserves `NonEmptyArray`. Use this when you need a distinct * reference, for example before mutating the returned array. * * **Example** (Copying an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * const original = [1, 2, 3] * const copied = Array.copy(original) * * copied // => [1, 2, 3] * original === copied // => false * ``` * * @see {@link fromIterable} — returns the same reference for arrays * * @stability stable * @category transforming * @since 2.0.0 */ (self: NonEmptyReadonlyArray): NonEmptyArray; /** * Creates a shallow copy of an array. * * **When to use** * * Use to create a distinct array reference for an existing array, for example * before mutating the returned array. * * **Details** * * The return type preserves `NonEmptyArray`. Use this when you need a distinct * reference, for example before mutating the returned array. * * **Example** (Copying an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * const original = [1, 2, 3] * const copied = Array.copy(original) * * copied // => [1, 2, 3] * original === copied // => false * ``` * * @see {@link fromIterable} — returns the same reference for arrays * * @stability stable * @category transforming * @since 2.0.0 */ (self: ReadonlyArray): Array; }; /** * Pads or truncates an array to exactly `n` elements, filling with `fill` * if the array is shorter, or slicing if longer. * * **When to use** * * Use to ensure an array has a specific length, padding with a fill value or truncating as needed. * * **Details** * * `n` is rounded down. `NaN` and non-positive values are treated as `0`, which * returns an empty array. * * **Example** (Padding an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.pad([1, 2, 3], 6, 0) // => [1, 2, 3, 0, 0, 0] * ``` * * @see {@link take} — truncate without padding * @see {@link replicate} — create an array of a single repeated value * * @stability stable * @category transforming * @since 3.8.4 */ export declare const pad: { /** * Pads or truncates an array to exactly `n` elements, filling with `fill` * if the array is shorter, or slicing if longer. * * **When to use** * * Use to ensure an array has a specific length, padding with a fill value or truncating as needed. * * **Details** * * `n` is rounded down. `NaN` and non-positive values are treated as `0`, which * returns an empty array. * * **Example** (Padding an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.pad([1, 2, 3], 6, 0) // => [1, 2, 3, 0, 0, 0] * ``` * * @see {@link take} — truncate without padding * @see {@link replicate} — create an array of a single repeated value * * @stability stable * @category transforming * @since 3.8.4 */ (n: number, fill: T): (self: Array) => Array; /** * Pads or truncates an array to exactly `n` elements, filling with `fill` * if the array is shorter, or slicing if longer. * * **When to use** * * Use to ensure an array has a specific length, padding with a fill value or truncating as needed. * * **Details** * * `n` is rounded down. `NaN` and non-positive values are treated as `0`, which * returns an empty array. * * **Example** (Padding an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.pad([1, 2, 3], 6, 0) // => [1, 2, 3, 0, 0, 0] * ``` * * @see {@link take} — truncate without padding * @see {@link replicate} — create an array of a single repeated value * * @stability stable * @category transforming * @since 3.8.4 */ (self: Array, n: number, fill: T): Array; }; /** * Splits an iterable into chunks of length `n`. The last chunk may be shorter * if `n` does not evenly divide the length. * * **When to use** * * Use to divide an iterable into a new array of non-overlapping chunks with a * maximum chunk size. * * **Details** * * `n` is rounded down and normalized to at least `1`; `NaN` and non-positive * values therefore produce singleton chunks. `chunksOf(n)([])` is `[]`, not * `[[]]`. Each chunk is a `NonEmptyArray`, and the outer return type preserves * `NonEmptyArray`. * * **Example** (Chunking an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.chunksOf([1, 2, 3, 4, 5], 2) // => [[1, 2], [3, 4], [5]] * ``` * * @see {@link split} — split into a given number of groups * @see {@link window} — sliding windows * * @stability stable * @category splitting * @since 2.0.0 */ export declare const chunksOf: { /** * Splits an iterable into chunks of length `n`. The last chunk may be shorter * if `n` does not evenly divide the length. * * **When to use** * * Use to divide an iterable into a new array of non-overlapping chunks with a * maximum chunk size. * * **Details** * * `n` is rounded down and normalized to at least `1`; `NaN` and non-positive * values therefore produce singleton chunks. `chunksOf(n)([])` is `[]`, not * `[[]]`. Each chunk is a `NonEmptyArray`, and the outer return type preserves * `NonEmptyArray`. * * **Example** (Chunking an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.chunksOf([1, 2, 3, 4, 5], 2) // => [[1, 2], [3, 4], [5]] * ``` * * @see {@link split} — split into a given number of groups * @see {@link window} — sliding windows * * @stability stable * @category splitting * @since 2.0.0 */ (n: number): >(self: S) => ReadonlyArray.With>>; /** * Splits an iterable into chunks of length `n`. The last chunk may be shorter * if `n` does not evenly divide the length. * * **When to use** * * Use to divide an iterable into a new array of non-overlapping chunks with a * maximum chunk size. * * **Details** * * `n` is rounded down and normalized to at least `1`; `NaN` and non-positive * values therefore produce singleton chunks. `chunksOf(n)([])` is `[]`, not * `[[]]`. Each chunk is a `NonEmptyArray`, and the outer return type preserves * `NonEmptyArray`. * * **Example** (Chunking an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.chunksOf([1, 2, 3, 4, 5], 2) // => [[1, 2], [3, 4], [5]] * ``` * * @see {@link split} — split into a given number of groups * @see {@link window} — sliding windows * * @stability stable * @category splitting * @since 2.0.0 */ (self: NonEmptyReadonlyArray, n: number): NonEmptyArray>; /** * Splits an iterable into chunks of length `n`. The last chunk may be shorter * if `n` does not evenly divide the length. * * **When to use** * * Use to divide an iterable into a new array of non-overlapping chunks with a * maximum chunk size. * * **Details** * * `n` is rounded down and normalized to at least `1`; `NaN` and non-positive * values therefore produce singleton chunks. `chunksOf(n)([])` is `[]`, not * `[[]]`. Each chunk is a `NonEmptyArray`, and the outer return type preserves * `NonEmptyArray`. * * **Example** (Chunking an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.chunksOf([1, 2, 3, 4, 5], 2) // => [[1, 2], [3, 4], [5]] * ``` * * @see {@link split} — split into a given number of groups * @see {@link window} — sliding windows * * @stability stable * @category splitting * @since 2.0.0 */ (self: Iterable, n: number): Array>; }; /** * Creates overlapping sliding windows of size `n`. * * **When to use** * * Use to process sequences with a moving window, such as for computing running averages or detecting patterns. * * **Details** * * `n` is rounded down, with `NaN` and non-positive values treated as `0`. * Returns an empty array if the normalized size is `0` or exceeds the array * length. Each window is a tuple of exactly the normalized size. * * **Example** (Creating sliding windows) * * ```ts import.meta.vitest * import { Array } from "effect" * * const values = [1, 2, 3, 4, 5] * * Array.window(values, 3) // => [[1, 2, 3], [2, 3, 4], [3, 4, 5]] * Array.window(values, 6) // => [] * ``` * * @see {@link chunksOf} — non-overlapping chunks * * @stability stable * @category splitting * @since 3.13.2 */ export declare const window: { /** * Creates overlapping sliding windows of size `n`. * * **When to use** * * Use to process sequences with a moving window, such as for computing running averages or detecting patterns. * * **Details** * * `n` is rounded down, with `NaN` and non-positive values treated as `0`. * Returns an empty array if the normalized size is `0` or exceeds the array * length. Each window is a tuple of exactly the normalized size. * * **Example** (Creating sliding windows) * * ```ts import.meta.vitest * import { Array } from "effect" * * const values = [1, 2, 3, 4, 5] * * Array.window(values, 3) // => [[1, 2, 3], [2, 3, 4], [3, 4, 5]] * Array.window(values, 6) // => [] * ``` * * @see {@link chunksOf} — non-overlapping chunks * * @stability stable * @category splitting * @since 3.13.2 */ (n: N): (self: Iterable) => Array>; /** * Creates overlapping sliding windows of size `n`. * * **When to use** * * Use to process sequences with a moving window, such as for computing running averages or detecting patterns. * * **Details** * * `n` is rounded down, with `NaN` and non-positive values treated as `0`. * Returns an empty array if the normalized size is `0` or exceeds the array * length. Each window is a tuple of exactly the normalized size. * * **Example** (Creating sliding windows) * * ```ts import.meta.vitest * import { Array } from "effect" * * const values = [1, 2, 3, 4, 5] * * Array.window(values, 3) // => [[1, 2, 3], [2, 3, 4], [3, 4, 5]] * Array.window(values, 6) // => [] * ``` * * @see {@link chunksOf} — non-overlapping chunks * * @stability stable * @category splitting * @since 3.13.2 */ (self: Iterable, n: N): Array>; }; /** * Groups consecutive equal elements using a custom equivalence function. * * **When to use** * * Use when you already have a non-empty array arranged so matching elements are * adjacent and need a custom equivalence function. * * **Details** * * Only adjacent elements are grouped. Non-adjacent duplicates stay separate. * Requires a `NonEmptyReadonlyArray`. * * **Example** (Grouping consecutive equal elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.groupWith( * ["a", "a", "b", "b", "b", "c", "a"], * (x, y) => x === y * ) // => [["a", "a"], ["b", "b", "b"], ["c"], ["a"]] * ``` * * @see {@link group} for grouping adjacent elements with `Equal.asEquivalence()` * @see {@link groupBy} for grouping all elements into a record by key, regardless of adjacency * * @stability stable * @category grouping * @since 2.0.0 */ export declare const groupWith: { /** * Groups consecutive equal elements using a custom equivalence function. * * **When to use** * * Use when you already have a non-empty array arranged so matching elements are * adjacent and need a custom equivalence function. * * **Details** * * Only adjacent elements are grouped. Non-adjacent duplicates stay separate. * Requires a `NonEmptyReadonlyArray`. * * **Example** (Grouping consecutive equal elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.groupWith( * ["a", "a", "b", "b", "b", "c", "a"], * (x, y) => x === y * ) // => [["a", "a"], ["b", "b", "b"], ["c"], ["a"]] * ``` * * @see {@link group} for grouping adjacent elements with `Equal.asEquivalence()` * @see {@link groupBy} for grouping all elements into a record by key, regardless of adjacency * * @stability stable * @category grouping * @since 2.0.0 */ (isEquivalent: (self: A, that: A) => boolean): (self: NonEmptyReadonlyArray) => NonEmptyArray>; /** * Groups consecutive equal elements using a custom equivalence function. * * **When to use** * * Use when you already have a non-empty array arranged so matching elements are * adjacent and need a custom equivalence function. * * **Details** * * Only adjacent elements are grouped. Non-adjacent duplicates stay separate. * Requires a `NonEmptyReadonlyArray`. * * **Example** (Grouping consecutive equal elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.groupWith( * ["a", "a", "b", "b", "b", "c", "a"], * (x, y) => x === y * ) // => [["a", "a"], ["b", "b", "b"], ["c"], ["a"]] * ``` * * @see {@link group} for grouping adjacent elements with `Equal.asEquivalence()` * @see {@link groupBy} for grouping all elements into a record by key, regardless of adjacency * * @stability stable * @category grouping * @since 2.0.0 */ (self: NonEmptyReadonlyArray, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray>; }; /** * Groups consecutive equal elements using `Equal.asEquivalence()`. * * **When to use** * * Use when you already have adjacent equal values and Effect's default equality * is the right comparison. * * **Details** * * Only adjacent elements are grouped. * * **Example** (Grouping adjacent equal elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.group([1, 1, 2, 2, 2, 3, 1]) // => [[1, 1], [2, 2, 2], [3], [1]] * ``` * * @see {@link groupWith} — use custom equality * @see {@link groupBy} — group by a key function into a record * * @stability stable * @category grouping * @since 2.0.0 */ export declare const group: (self: NonEmptyReadonlyArray) => NonEmptyArray>; /** * Groups elements into a record by a key-returning function. Each key maps * to a `NonEmptyArray` of elements that produced that key. * * **When to use** * * Use to build buckets of elements indexed by a computed string or symbol key. * * **Details** * * Unlike `group` and `groupWith`, elements do not need to be adjacent to be * grouped together. The key function must return a `string` or `symbol`. * * **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 property) * * ```ts import.meta.vitest * import { Array } from "effect" * * const people = [ * { name: "Alice", group: "A" }, * { name: "Bob", group: "B" }, * { name: "Charlie", group: "A" } * ] * * Object.keys(Array.groupBy(people, (person) => person.group)).join(",") // => "A,B" * ``` * * @see {@link group} — group adjacent equal elements * @see {@link groupWith} — group adjacent elements by custom equality * * @stability stable * @category grouping * @since 2.0.0 */ export declare const groupBy: { /** * Groups elements into a record by a key-returning function. Each key maps * to a `NonEmptyArray` of elements that produced that key. * * **When to use** * * Use to build buckets of elements indexed by a computed string or symbol key. * * **Details** * * Unlike `group` and `groupWith`, elements do not need to be adjacent to be * grouped together. The key function must return a `string` or `symbol`. * * **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 property) * * ```ts import.meta.vitest * import { Array } from "effect" * * const people = [ * { name: "Alice", group: "A" }, * { name: "Bob", group: "B" }, * { name: "Charlie", group: "A" } * ] * * Object.keys(Array.groupBy(people, (person) => person.group)).join(",") // => "A,B" * ``` * * @see {@link group} — group adjacent equal elements * @see {@link groupWith} — group adjacent elements by custom equality * * @stability stable * @category grouping * @since 2.0.0 */ (f: (a: A) => K): (self: Iterable) => Record.ReadonlyRecord.GroupByResult>; /** * Groups elements into a record by a key-returning function. Each key maps * to a `NonEmptyArray` of elements that produced that key. * * **When to use** * * Use to build buckets of elements indexed by a computed string or symbol key. * * **Details** * * Unlike `group` and `groupWith`, elements do not need to be adjacent to be * grouped together. The key function must return a `string` or `symbol`. * * **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 property) * * ```ts import.meta.vitest * import { Array } from "effect" * * const people = [ * { name: "Alice", group: "A" }, * { name: "Bob", group: "B" }, * { name: "Charlie", group: "A" } * ] * * Object.keys(Array.groupBy(people, (person) => person.group)).join(",") // => "A,B" * ``` * * @see {@link group} — group adjacent equal elements * @see {@link groupWith} — group adjacent elements by custom equality * * @stability stable * @category grouping * @since 2.0.0 */ (self: Iterable, f: (a: A) => K): Record.ReadonlyRecord.GroupByResult>; }; /** * Computes the union of two iterables using a custom equivalence. * * **When to use** * * Use when you need the union of two arrays but duplicate detection must use a * custom equivalence instead of the default `Equal.asEquivalence()`. * * **Details** * * Keeps the elements of `self`, then appends elements of `that` that have no * equivalent in `self`. Calls `isEquivalent` with an element from `self` first * and an element from `that` second. * * **Gotchas** * * Each input must already be deduplicated. * * **Example** (Computing unions with custom equality) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.unionWith([1, 2], [2, 3], (a, b) => a === b) // => [1, 2, 3] * ``` * * @see {@link union} for the `Equal.asEquivalence()` variant * @see {@link intersectionWith} for keeping elements present in both arrays * @see {@link differenceWith} for keeping elements present only in the first array * * @stability stable * @category set operations * @since 2.0.0 */ export declare const unionWith: { /** * Computes the union of two iterables using a custom equivalence. * * **When to use** * * Use when you need the union of two arrays but duplicate detection must use a * custom equivalence instead of the default `Equal.asEquivalence()`. * * **Details** * * Keeps the elements of `self`, then appends elements of `that` that have no * equivalent in `self`. Calls `isEquivalent` with an element from `self` first * and an element from `that` second. * * **Gotchas** * * Each input must already be deduplicated. * * **Example** (Computing unions with custom equality) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.unionWith([1, 2], [2, 3], (a, b) => a === b) // => [1, 2, 3] * ``` * * @see {@link union} for the `Equal.asEquivalence()` variant * @see {@link intersectionWith} for keeping elements present in both arrays * @see {@link differenceWith} for keeping elements present only in the first array * * @stability stable * @category set operations * @since 2.0.0 */ , T extends Iterable>(that: T, isEquivalent: (self: ReadonlyArray.Infer, that: ReadonlyArray.Infer) => boolean): (self: S) => ReadonlyArray.OrNonEmpty | ReadonlyArray.Infer>; /** * Computes the union of two iterables using a custom equivalence. * * **When to use** * * Use when you need the union of two arrays but duplicate detection must use a * custom equivalence instead of the default `Equal.asEquivalence()`. * * **Details** * * Keeps the elements of `self`, then appends elements of `that` that have no * equivalent in `self`. Calls `isEquivalent` with an element from `self` first * and an element from `that` second. * * **Gotchas** * * Each input must already be deduplicated. * * **Example** (Computing unions with custom equality) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.unionWith([1, 2], [2, 3], (a, b) => a === b) // => [1, 2, 3] * ``` * * @see {@link union} for the `Equal.asEquivalence()` variant * @see {@link intersectionWith} for keeping elements present in both arrays * @see {@link differenceWith} for keeping elements present only in the first array * * @stability stable * @category set operations * @since 2.0.0 */ (self: NonEmptyReadonlyArray, that: Iterable, isEquivalent: (self: A, that: B) => boolean): NonEmptyArray; /** * Computes the union of two iterables using a custom equivalence. * * **When to use** * * Use when you need the union of two arrays but duplicate detection must use a * custom equivalence instead of the default `Equal.asEquivalence()`. * * **Details** * * Keeps the elements of `self`, then appends elements of `that` that have no * equivalent in `self`. Calls `isEquivalent` with an element from `self` first * and an element from `that` second. * * **Gotchas** * * Each input must already be deduplicated. * * **Example** (Computing unions with custom equality) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.unionWith([1, 2], [2, 3], (a, b) => a === b) // => [1, 2, 3] * ``` * * @see {@link union} for the `Equal.asEquivalence()` variant * @see {@link intersectionWith} for keeping elements present in both arrays * @see {@link differenceWith} for keeping elements present only in the first array * * @stability stable * @category set operations * @since 2.0.0 */ (self: Iterable, that: NonEmptyReadonlyArray, isEquivalent: (self: A, that: B) => boolean): NonEmptyArray; /** * Computes the union of two iterables using a custom equivalence. * * **When to use** * * Use when you need the union of two arrays but duplicate detection must use a * custom equivalence instead of the default `Equal.asEquivalence()`. * * **Details** * * Keeps the elements of `self`, then appends elements of `that` that have no * equivalent in `self`. Calls `isEquivalent` with an element from `self` first * and an element from `that` second. * * **Gotchas** * * Each input must already be deduplicated. * * **Example** (Computing unions with custom equality) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.unionWith([1, 2], [2, 3], (a, b) => a === b) // => [1, 2, 3] * ``` * * @see {@link union} for the `Equal.asEquivalence()` variant * @see {@link intersectionWith} for keeping elements present in both arrays * @see {@link differenceWith} for keeping elements present only in the first array * * @stability stable * @category set operations * @since 2.0.0 */ (self: Iterable, that: Iterable, isEquivalent: (self: A, that: B) => boolean): Array; }; /** * Computes the union of two iterables using `Equal.asEquivalence()`. * * **Gotchas** * * Each input must already be deduplicated. Use {@link dedupe} to remove * duplicates from an input first. * * **Example** (Computing array unions) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.union([1, 2], [2, 3]) // => [1, 2, 3] * ``` * * @see {@link unionWith} — use custom equality * @see {@link intersection} — elements in both arrays * @see {@link difference} — elements only in the first array * * @stability stable * @category set operations * @since 2.0.0 */ export declare const union: { /** * Computes the union of two iterables using `Equal.asEquivalence()`. * * **Gotchas** * * Each input must already be deduplicated. Use {@link dedupe} to remove * duplicates from an input first. * * **Example** (Computing array unions) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.union([1, 2], [2, 3]) // => [1, 2, 3] * ``` * * @see {@link unionWith} — use custom equality * @see {@link intersection} — elements in both arrays * @see {@link difference} — elements only in the first array * * @stability stable * @category set operations * @since 2.0.0 */ >(that: T): >(self: S) => ReadonlyArray.OrNonEmpty | ReadonlyArray.Infer>; /** * Computes the union of two iterables using `Equal.asEquivalence()`. * * **Gotchas** * * Each input must already be deduplicated. Use {@link dedupe} to remove * duplicates from an input first. * * **Example** (Computing array unions) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.union([1, 2], [2, 3]) // => [1, 2, 3] * ``` * * @see {@link unionWith} — use custom equality * @see {@link intersection} — elements in both arrays * @see {@link difference} — elements only in the first array * * @stability stable * @category set operations * @since 2.0.0 */ (self: NonEmptyReadonlyArray, that: ReadonlyArray): NonEmptyArray; /** * Computes the union of two iterables using `Equal.asEquivalence()`. * * **Gotchas** * * Each input must already be deduplicated. Use {@link dedupe} to remove * duplicates from an input first. * * **Example** (Computing array unions) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.union([1, 2], [2, 3]) // => [1, 2, 3] * ``` * * @see {@link unionWith} — use custom equality * @see {@link intersection} — elements in both arrays * @see {@link difference} — elements only in the first array * * @stability stable * @category set operations * @since 2.0.0 */ (self: ReadonlyArray, that: NonEmptyReadonlyArray): NonEmptyArray; /** * Computes the union of two iterables using `Equal.asEquivalence()`. * * **Gotchas** * * Each input must already be deduplicated. Use {@link dedupe} to remove * duplicates from an input first. * * **Example** (Computing array unions) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.union([1, 2], [2, 3]) // => [1, 2, 3] * ``` * * @see {@link unionWith} — use custom equality * @see {@link intersection} — elements in both arrays * @see {@link difference} — elements only in the first array * * @stability stable * @category set operations * @since 2.0.0 */ (self: Iterable, that: Iterable): Array; }; /** * Computes the intersection of two arrays using a custom equivalence. Order is * determined by the first array. * * **When to use** * * Use when you need to keep only values present in both arrays and equality * must be defined by a custom comparator, such as matching objects by id. * * **Example** (Computing intersections with custom equality) * * ```ts import.meta.vitest * import { Array } from "effect" * * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }] * const array2 = [{ id: 3 }, { id: 4 }, { id: 1 }] * const isEquivalent = (a: { id: number }, b: { id: number }) => a.id === b.id * * Array.intersectionWith(isEquivalent)(array2)(array1) // => [{ id: 1 }, { id: 3 }] * ``` * * @see {@link intersection} for the `Equal.asEquivalence()` variant * @see {@link unionWith} for keeping values from either array with custom equality * @see {@link differenceWith} for keeping values only from the first array with custom equality * * @stability stable * @category set operations * @since 2.0.0 */ export declare const intersectionWith: (isEquivalent: (self: A, that: A) => boolean) => { (that: Iterable): (self: Iterable) => Array; (self: Iterable, that: Iterable): Array; }; /** * Computes the intersection of two arrays using `Equal.asEquivalence()`. Order is * determined by the first array. * * **When to use** * * Use when Effect equality is the right membership test and you want to keep * values present in both inputs while preserving the first input's order. * * **Example** (Computing array intersections) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.intersection([1, 2, 3], [3, 4, 1]) // => [1, 3] * ``` * * @see {@link intersectionWith} — use custom equality * @see {@link union} — elements in either array * @see {@link difference} — elements only in the first array * * @stability stable * @category set operations * @since 2.0.0 */ export declare const intersection: { /** * Computes the intersection of two arrays using `Equal.asEquivalence()`. Order is * determined by the first array. * * **When to use** * * Use when Effect equality is the right membership test and you want to keep * values present in both inputs while preserving the first input's order. * * **Example** (Computing array intersections) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.intersection([1, 2, 3], [3, 4, 1]) // => [1, 3] * ``` * * @see {@link intersectionWith} — use custom equality * @see {@link union} — elements in either array * @see {@link difference} — elements only in the first array * * @stability stable * @category set operations * @since 2.0.0 */ (that: Iterable): (self: Iterable) => Array; /** * Computes the intersection of two arrays using `Equal.asEquivalence()`. Order is * determined by the first array. * * **When to use** * * Use when Effect equality is the right membership test and you want to keep * values present in both inputs while preserving the first input's order. * * **Example** (Computing array intersections) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.intersection([1, 2, 3], [3, 4, 1]) // => [1, 3] * ``` * * @see {@link intersectionWith} — use custom equality * @see {@link union} — elements in either array * @see {@link difference} — elements only in the first array * * @stability stable * @category set operations * @since 2.0.0 */ (self: Iterable, that: Iterable): Array; }; /** * Computes elements in the first array that are not in the second, using a * custom equivalence. * * **When to use** * * Use when you need to keep only values from the first array and equality must * be defined by a custom comparator, such as matching objects by id. * * **Example** (Computing differences with custom equality) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.differenceWith((a, b) => a === b)([1, 2, 3], [2, 3, 4]) // => [1] * ``` * * @see {@link difference} for the `Equal.asEquivalence()` variant * @see {@link unionWith} for keeping values from either array with custom equality * @see {@link intersectionWith} for keeping values present in both arrays with custom equality * * @stability stable * @category set operations * @since 2.0.0 */ export declare const differenceWith: (isEquivalent: (self: A, that: A) => boolean) => { (that: Iterable): (self: Iterable) => Array; (self: Iterable, that: Iterable): Array; }; /** * Computes elements in the first array that are not in the second, using * `Equal.asEquivalence()`. * * **When to use** * * Use when you need to keep values from the first array that are absent from * the second and the default `Equal.asEquivalence()` comparison is appropriate. * * **Example** (Computing array differences) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.difference([1, 2, 3], [2, 3, 4]) // => [1] * ``` * * @see {@link differenceWith} — use custom equality * @see {@link union} — elements in either array * @see {@link intersection} — elements in both arrays * * @stability stable * @category set operations * @since 2.0.0 */ export declare const difference: { /** * Computes elements in the first array that are not in the second, using * `Equal.asEquivalence()`. * * **When to use** * * Use when you need to keep values from the first array that are absent from * the second and the default `Equal.asEquivalence()` comparison is appropriate. * * **Example** (Computing array differences) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.difference([1, 2, 3], [2, 3, 4]) // => [1] * ``` * * @see {@link differenceWith} — use custom equality * @see {@link union} — elements in either array * @see {@link intersection} — elements in both arrays * * @stability stable * @category set operations * @since 2.0.0 */ (that: Iterable): (self: Iterable) => Array; /** * Computes elements in the first array that are not in the second, using * `Equal.asEquivalence()`. * * **When to use** * * Use when you need to keep values from the first array that are absent from * the second and the default `Equal.asEquivalence()` comparison is appropriate. * * **Example** (Computing array differences) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.difference([1, 2, 3], [2, 3, 4]) // => [1] * ``` * * @see {@link differenceWith} — use custom equality * @see {@link union} — elements in either array * @see {@link intersection} — elements in both arrays * * @stability stable * @category set operations * @since 2.0.0 */ (self: Iterable, that: Iterable): Array; }; /** * Creates an empty array. * * **When to use** * * Use to create a typed empty array without allocating placeholder elements. * * **Example** (Creating an empty array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.empty() // => [] * ``` * * @see {@link of} — create a single-element array * @see {@link make} — create from multiple values * * @stability stable * @category constructors * @since 2.0.0 */ export declare const empty: () => Array; /** * Wraps a single value in a `NonEmptyArray`. * * **Example** (Creating a single-element array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.of(1) // => [1] * ``` * * @see {@link make} — create from multiple values * @see {@link empty} — create an empty array * * @stability stable * @category constructors * @since 2.0.0 */ export declare const of: (a: A) => NonEmptyArray; /** * Utility types for working with `ReadonlyArray` at the type level. Use these * to infer element types, preserve non-emptiness, and flatten nested arrays. * * @stability stable * @since 2.0.0 */ export declare namespace ReadonlyArray { /** * Infers the element type of an iterable. * * **Example** (Inferring an element type) * * ```ts import.meta.vitest * import type { Array } from "effect" * * type StringArrayType = Array.ReadonlyArray.Infer> * // StringArrayType is string * ``` * * @category utility types * @since 2.0.0 */ type Infer> = S extends ReadonlyArray ? A : S extends Iterable ? A : never; /** * Constructs an array type preserving non-emptiness. * * **Example** (Preserving non-emptiness) * * ```ts import.meta.vitest * import type { Array } from "effect" * * type Result = Array.ReadonlyArray.With * // Result is NonEmptyArray * ``` * * @category utility types * @since 2.0.0 */ type With, A> = S extends NonEmptyReadonlyArray ? NonEmptyArray : Array; /** * Creates a non-empty array if either input is non-empty. * * **Example** (Preserving non-emptiness from either input) * * ```ts import.meta.vitest * import type { Array } from "effect" * * type Result = Array.ReadonlyArray.OrNonEmpty< * readonly [number], * ReadonlyArray, * number * > * // Result is NonEmptyArray * ``` * * @category utility types * @since 2.0.0 */ type OrNonEmpty, T extends Iterable, A> = S extends NonEmptyReadonlyArray ? NonEmptyArray : T extends NonEmptyReadonlyArray ? NonEmptyArray : Array; /** * Creates a non-empty array only if both inputs are non-empty. * * **Example** (Preserving non-emptiness from both inputs) * * ```ts import.meta.vitest * import type { Array } from "effect" * * type Result = Array.ReadonlyArray.AndNonEmpty< * readonly [number], * readonly [string], * boolean * > * // Result is NonEmptyArray * ``` * * @category utility types * @since 2.0.0 */ type AndNonEmpty, T extends Iterable, A> = S extends NonEmptyReadonlyArray ? T extends NonEmptyReadonlyArray ? NonEmptyArray : Array : Array; /** * Flattens a nested array type. * * **Example** (Flattening nested array types) * * ```ts import.meta.vitest * import type { Array } from "effect" * * type Nested = ReadonlyArray> * type Flattened = Array.ReadonlyArray.Flatten * // Flattened is Array * ``` * * @category utility types * @since 2.0.0 */ type Flatten>> = T extends NonEmptyReadonlyArray> ? NonEmptyArray : Array; } /** * Transforms each element using a function, returning a new array. * * **When to use** * * Use to transform each element independently while preserving the array shape. * * **Details** * * The function receives `(element, index)`. The return type preserves * `NonEmptyArray`. * * **Example** (Doubling values) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.map([1, 2, 3], (x) => x * 2) // => [2, 4, 6] * ``` * * @see {@link flatMap} — map and flatten * * @stability stable * @category mapping * @since 2.0.0 */ export declare const map: { /** * Transforms each element using a function, returning a new array. * * **When to use** * * Use to transform each element independently while preserving the array shape. * * **Details** * * The function receives `(element, index)`. The return type preserves * `NonEmptyArray`. * * **Example** (Doubling values) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.map([1, 2, 3], (x) => x * 2) // => [2, 4, 6] * ``` * * @see {@link flatMap} — map and flatten * * @stability stable * @category mapping * @since 2.0.0 */ , B>(f: (a: ReadonlyArray.Infer, i: number) => B): (self: S) => ReadonlyArray.With; /** * Transforms each element using a function, returning a new array. * * **When to use** * * Use to transform each element independently while preserving the array shape. * * **Details** * * The function receives `(element, index)`. The return type preserves * `NonEmptyArray`. * * **Example** (Doubling values) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.map([1, 2, 3], (x) => x * 2) // => [2, 4, 6] * ``` * * @see {@link flatMap} — map and flatten * * @stability stable * @category mapping * @since 2.0.0 */ , B>(self: S, f: (a: ReadonlyArray.Infer, i: number) => B): ReadonlyArray.With; }; /** * Maps each element to an array and flattens the results into a single array. * * **When to use** * * Use to map each array element to zero or more values and concatenate the * results in one pass. * * **Details** * * The function receives `(element, index)`. This returns `NonEmptyArray` when * both the input and mapped arrays are non-empty. * * **Example** (Flat mapping an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.flatMap([1, 2, 3], (x) => [x, x * 2]) // => [1, 2, 2, 4, 3, 6] * ``` * * @see {@link map} — transform without flattening * @see {@link flatten} — flatten without mapping * * @stability stable * @category sequencing * @since 2.0.0 */ export declare const flatMap: { /** * Maps each element to an array and flattens the results into a single array. * * **When to use** * * Use to map each array element to zero or more values and concatenate the * results in one pass. * * **Details** * * The function receives `(element, index)`. This returns `NonEmptyArray` when * both the input and mapped arrays are non-empty. * * **Example** (Flat mapping an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.flatMap([1, 2, 3], (x) => [x, x * 2]) // => [1, 2, 2, 4, 3, 6] * ``` * * @see {@link map} — transform without flattening * @see {@link flatten} — flatten without mapping * * @stability stable * @category sequencing * @since 2.0.0 */ , T extends ReadonlyArray>(f: (a: ReadonlyArray.Infer, i: number) => T): (self: S) => ReadonlyArray.AndNonEmpty>; /** * Maps each element to an array and flattens the results into a single array. * * **When to use** * * Use to map each array element to zero or more values and concatenate the * results in one pass. * * **Details** * * The function receives `(element, index)`. This returns `NonEmptyArray` when * both the input and mapped arrays are non-empty. * * **Example** (Flat mapping an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.flatMap([1, 2, 3], (x) => [x, x * 2]) // => [1, 2, 2, 4, 3, 6] * ``` * * @see {@link map} — transform without flattening * @see {@link flatten} — flatten without mapping * * @stability stable * @category sequencing * @since 2.0.0 */ (self: NonEmptyReadonlyArray, f: (a: A, i: number) => NonEmptyReadonlyArray): NonEmptyArray; /** * Maps each element to an array and flattens the results into a single array. * * **When to use** * * Use to map each array element to zero or more values and concatenate the * results in one pass. * * **Details** * * The function receives `(element, index)`. This returns `NonEmptyArray` when * both the input and mapped arrays are non-empty. * * **Example** (Flat mapping an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.flatMap([1, 2, 3], (x) => [x, x * 2]) // => [1, 2, 2, 4, 3, 6] * ``` * * @see {@link map} — transform without flattening * @see {@link flatten} — flatten without mapping * * @stability stable * @category sequencing * @since 2.0.0 */ (self: ReadonlyArray, f: (a: A, i: number) => ReadonlyArray): Array; }; /** * Flattens a nested array of arrays into a single array. * * **When to use** * * Use to collapse one level of nested arrays when no per-element mapping is * needed. * * **Example** (Flattening nested arrays) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.flatten([[1, 2], [], [3, 4], [], [5, 6]]) // => [1, 2, 3, 4, 5, 6] * ``` * * @see {@link flatMap} — map then flatten in one step * * @stability stable * @category sequencing * @since 2.0.0 */ export declare const flatten: >>(self: S) => ReadonlyArray.Flatten; /** * Extracts all `Some` values from an iterable of `Option`s, discarding `None`s. * * **When to use** * * Use to collect only present values from an iterable of `Option` values while * discarding `None` values. * * **Example** (Extracting Some values) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.getSomes([Option.some(1), Option.none(), Option.some(2)]) // => [1, 2] * ``` * * @see {@link fromOption} — convert a single Option * @see {@link getSuccesses} — extract successes from Results * * @stability stable * @category filtering * @since 2.0.0 */ export declare const getSomes: >, X = any>(self: T) => Array>>; /** * Extracts all failure values from an iterable of `Result`s, discarding * successes. * * **When to use** * * Use when you can drop the success channel and only need the failure * payloads, not the original result wrappers. * * **Example** (Extracting failures) * * ```ts import.meta.vitest * import { Array, Result } from "effect" * * Array.getFailures([Result.succeed(1), Result.fail("err"), Result.succeed(2)]) // => ["err"] * ``` * * @see {@link getSuccesses} — extract success values * @see {@link separate} — split into successes and failures * * @stability stable * @category filtering * @since 4.0.0 */ export declare const getFailures: >>(self: T) => Array>>; /** * Extracts all success values from an iterable of `Result`s, discarding * failures. * * **When to use** * * Use when you can drop the failure channel and only need the success * payloads, not the original result wrappers. * * **Example** (Extracting successes) * * ```ts import.meta.vitest * import { Array, Result } from "effect" * * Array.getSuccesses([Result.succeed(1), Result.fail("err"), Result.succeed(2)]) // => [1, 2] * ``` * * @see {@link getFailures} — extract failure values * @see {@link separate} — split into successes and failures * * @stability stable * @category filtering * @since 4.0.0 */ export declare const getSuccesses: >>(self: T) => Array>>; /** * Keeps transformed values for elements where a `Filter` succeeds. * * **When to use** * * Use to filter an iterable with a `Result`-returning transformation while * discarding failures. * * **Details** * * The filter receives `(element, index)`. Failures are discarded. * * **Example** (Filtering and transforming) * * ```ts import.meta.vitest * import { Array, Result } from "effect" * * Array.filterMap([1, 2, 3, 4], (n) => n % 2 === 0 ? Result.succeed(n * 10) : Result.failVoid) // => [20, 40] * ``` * * @see {@link filter} — keep original elements matching a predicate * @see {@link partition} for keeping both successes and failures * * @stability stable * @category filtering * @since 2.0.0 */ export declare const filterMap: { /** * Keeps transformed values for elements where a `Filter` succeeds. * * **When to use** * * Use to filter an iterable with a `Result`-returning transformation while * discarding failures. * * **Details** * * The filter receives `(element, index)`. Failures are discarded. * * **Example** (Filtering and transforming) * * ```ts import.meta.vitest * import { Array, Result } from "effect" * * Array.filterMap([1, 2, 3, 4], (n) => n % 2 === 0 ? Result.succeed(n * 10) : Result.failVoid) // => [20, 40] * ``` * * @see {@link filter} — keep original elements matching a predicate * @see {@link partition} for keeping both successes and failures * * @stability stable * @category filtering * @since 2.0.0 */ (f: (input: NoInfer, i: number) => Result.Result): (self: Iterable) => Array; /** * Keeps transformed values for elements where a `Filter` succeeds. * * **When to use** * * Use to filter an iterable with a `Result`-returning transformation while * discarding failures. * * **Details** * * The filter receives `(element, index)`. Failures are discarded. * * **Example** (Filtering and transforming) * * ```ts import.meta.vitest * import { Array, Result } from "effect" * * Array.filterMap([1, 2, 3, 4], (n) => n % 2 === 0 ? Result.succeed(n * 10) : Result.failVoid) // => [20, 40] * ``` * * @see {@link filter} — keep original elements matching a predicate * @see {@link partition} for keeping both successes and failures * * @stability stable * @category filtering * @since 2.0.0 */ (self: Iterable, f: (input: A, i: number) => Result.Result): Array; }; /** * Keeps only elements satisfying a predicate (or refinement). * * **When to use** * * Use to filter an iterable into a new array of original elements that satisfy * a boolean predicate or refinement. * * **Details** * * The predicate receives `(element, index)`. Refinements are supported for type * narrowing. * * **Example** (Filtering even numbers) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.filter([1, 2, 3, 4], (x) => x % 2 === 0) // => [2, 4] * ``` * * @see {@link partition} — split into matching and non-matching * @see {@link filterMap} for transforming while filtering * * @stability stable * @category filtering * @since 2.0.0 */ export declare const filter: { /** * Keeps only elements satisfying a predicate (or refinement). * * **When to use** * * Use to filter an iterable into a new array of original elements that satisfy * a boolean predicate or refinement. * * **Details** * * The predicate receives `(element, index)`. Refinements are supported for type * narrowing. * * **Example** (Filtering even numbers) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.filter([1, 2, 3, 4], (x) => x % 2 === 0) // => [2, 4] * ``` * * @see {@link partition} — split into matching and non-matching * @see {@link filterMap} for transforming while filtering * * @stability stable * @category filtering * @since 2.0.0 */ (refinement: (a: NoInfer, i: number) => a is B): (self: Iterable) => Array; /** * Keeps only elements satisfying a predicate (or refinement). * * **When to use** * * Use to filter an iterable into a new array of original elements that satisfy * a boolean predicate or refinement. * * **Details** * * The predicate receives `(element, index)`. Refinements are supported for type * narrowing. * * **Example** (Filtering even numbers) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.filter([1, 2, 3, 4], (x) => x % 2 === 0) // => [2, 4] * ``` * * @see {@link partition} — split into matching and non-matching * @see {@link filterMap} for transforming while filtering * * @stability stable * @category filtering * @since 2.0.0 */ (predicate: (a: NoInfer, i: number) => boolean): (self: Iterable) => Array; /** * Keeps only elements satisfying a predicate (or refinement). * * **When to use** * * Use to filter an iterable into a new array of original elements that satisfy * a boolean predicate or refinement. * * **Details** * * The predicate receives `(element, index)`. Refinements are supported for type * narrowing. * * **Example** (Filtering even numbers) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.filter([1, 2, 3, 4], (x) => x % 2 === 0) // => [2, 4] * ``` * * @see {@link partition} — split into matching and non-matching * @see {@link filterMap} for transforming while filtering * * @stability stable * @category filtering * @since 2.0.0 */ (self: Iterable, refinement: (a: A, i: number) => a is B): Array; /** * Keeps only elements satisfying a predicate (or refinement). * * **When to use** * * Use to filter an iterable into a new array of original elements that satisfy * a boolean predicate or refinement. * * **Details** * * The predicate receives `(element, index)`. Refinements are supported for type * narrowing. * * **Example** (Filtering even numbers) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.filter([1, 2, 3, 4], (x) => x % 2 === 0) // => [2, 4] * ``` * * @see {@link partition} — split into matching and non-matching * @see {@link filterMap} for transforming while filtering * * @stability stable * @category filtering * @since 2.0.0 */ (self: Iterable, predicate: (a: A, i: number) => boolean): Array; }; /** * Splits an iterable using a `Filter` into successes and failures. * * **When to use** * * Use to partition an iterable by evaluating each element with a * `Result`-returning filter and keeping both success and failure values. * * **Details** * * Returns `[passes, fails]`. The filter receives `(element, index)`. * * **Example** (Partitioning with a filter) * * ```ts import.meta.vitest * import { Array, Result } from "effect" * * Array.partition([1, -2, 3], (n, i) => * n > 0 ? Result.succeed(n + i) : Result.fail(`negative:${n}`) * ) // => [[1, 5], ["negative:-2"]] * ``` * * @see {@link filter} — keep only matching elements * @see {@link filterMap} for discarding failures * @see {@link separate} — split an iterable of `Result` values * * @stability stable * @category filtering * @since 2.0.0 */ export declare const partition: { /** * Splits an iterable using a `Filter` into successes and failures. * * **When to use** * * Use to partition an iterable by evaluating each element with a * `Result`-returning filter and keeping both success and failure values. * * **Details** * * Returns `[passes, fails]`. The filter receives `(element, index)`. * * **Example** (Partitioning with a filter) * * ```ts import.meta.vitest * import { Array, Result } from "effect" * * Array.partition([1, -2, 3], (n, i) => * n > 0 ? Result.succeed(n + i) : Result.fail(`negative:${n}`) * ) // => [[1, 5], ["negative:-2"]] * ``` * * @see {@link filter} — keep only matching elements * @see {@link filterMap} for discarding failures * @see {@link separate} — split an iterable of `Result` values * * @stability stable * @category filtering * @since 2.0.0 */ (f: (input: NoInfer, i: number) => Result.Result): (self: Iterable) => [passes: Array, fails: Array]; /** * Splits an iterable using a `Filter` into successes and failures. * * **When to use** * * Use to partition an iterable by evaluating each element with a * `Result`-returning filter and keeping both success and failure values. * * **Details** * * Returns `[passes, fails]`. The filter receives `(element, index)`. * * **Example** (Partitioning with a filter) * * ```ts import.meta.vitest * import { Array, Result } from "effect" * * Array.partition([1, -2, 3], (n, i) => * n > 0 ? Result.succeed(n + i) : Result.fail(`negative:${n}`) * ) // => [[1, 5], ["negative:-2"]] * ``` * * @see {@link filter} — keep only matching elements * @see {@link filterMap} for discarding failures * @see {@link separate} — split an iterable of `Result` values * * @stability stable * @category filtering * @since 2.0.0 */ (self: Iterable, f: (input: A, i: number) => Result.Result): [passes: Array, fails: Array]; }; /** * Separates an iterable of `Result`s into success values and failure values. * * **When to use** * * Use to split an iterable of `Result` values into success and failure arrays. * * **Details** * * Returns `[successes, failures]`. This is equivalent to * `partition(identity)`. * * **Example** (Separating Results) * * ```ts import.meta.vitest * import { Array, Result } from "effect" * * Array.separate([Result.succeed(1), Result.fail("error"), Result.succeed(2)]) // => [[1, 2], ["error"]] * ``` * * @see {@link getFailures} — extract only failures * @see {@link getSuccesses} — extract only successes * @see {@link partition} for computing `Result` values while splitting * * @stability stable * @category filtering * @since 2.0.0 */ export declare const separate: >>(self: T) => [ successes: Array>>, failures: Array>> ]; /** * Folds an iterable from left to right into a single value. * * **When to use** * * Use to combine all elements into one accumulated value from left to right. * * **Details** * * The function receives `(accumulator, element, index)`. * * **Example** (Summing an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.reduce([1, 2, 3], 0, (acc, n) => acc + n) // => 6 * ``` * * @see {@link reduceRight} — fold from right to left * @see {@link scan} — fold keeping intermediate values * * @stability stable * @category folding * @since 2.0.0 */ export declare const reduce: { /** * Folds an iterable from left to right into a single value. * * **When to use** * * Use to combine all elements into one accumulated value from left to right. * * **Details** * * The function receives `(accumulator, element, index)`. * * **Example** (Summing an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.reduce([1, 2, 3], 0, (acc, n) => acc + n) // => 6 * ``` * * @see {@link reduceRight} — fold from right to left * @see {@link scan} — fold keeping intermediate values * * @stability stable * @category folding * @since 2.0.0 */ (b: B, f: (b: B, a: A, i: number) => B): (self: Iterable) => B; /** * Folds an iterable from left to right into a single value. * * **When to use** * * Use to combine all elements into one accumulated value from left to right. * * **Details** * * The function receives `(accumulator, element, index)`. * * **Example** (Summing an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.reduce([1, 2, 3], 0, (acc, n) => acc + n) // => 6 * ``` * * @see {@link reduceRight} — fold from right to left * @see {@link scan} — fold keeping intermediate values * * @stability stable * @category folding * @since 2.0.0 */ (self: Iterable, b: B, f: (b: B, a: A, i: number) => B): B; }; /** * Folds an iterable from right to left into a single value. * * **When to use** * * Use when you need to fold values from right to left. * * **Details** * * The function receives `(accumulator, element, index)`. * * **Example** (Folding from right to left) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.reduceRight([1, 2, 3], 0, (acc, n) => acc + n) // => 6 * ``` * * @see {@link reduce} — fold from left to right * @see {@link scanRight} — fold keeping intermediate values * * @stability stable * @category folding * @since 2.0.0 */ export declare const reduceRight: { /** * Folds an iterable from right to left into a single value. * * **When to use** * * Use when you need to fold values from right to left. * * **Details** * * The function receives `(accumulator, element, index)`. * * **Example** (Folding from right to left) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.reduceRight([1, 2, 3], 0, (acc, n) => acc + n) // => 6 * ``` * * @see {@link reduce} — fold from left to right * @see {@link scanRight} — fold keeping intermediate values * * @stability stable * @category folding * @since 2.0.0 */ (b: B, f: (b: B, a: A, i: number) => B): (self: Iterable) => B; /** * Folds an iterable from right to left into a single value. * * **When to use** * * Use when you need to fold values from right to left. * * **Details** * * The function receives `(accumulator, element, index)`. * * **Example** (Folding from right to left) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.reduceRight([1, 2, 3], 0, (acc, n) => acc + n) // => 6 * ``` * * @see {@link reduce} — fold from left to right * @see {@link scanRight} — fold keeping intermediate values * * @stability stable * @category folding * @since 2.0.0 */ (self: Iterable, b: B, f: (b: B, a: A, i: number) => B): B; }; /** * Lifts a predicate into an array: returns `[value]` if the predicate holds, * `[]` otherwise. * * **Example** (Wrapping values conditionally) * * ```ts import.meta.vitest * import { Array } from "effect" * * const fromEven = Array.liftPredicate((n: number) => n % 2 === 0) * * fromEven(1) // => [] * fromEven(2) // => [2] * ``` * * @see {@link liftOption} — lift an Option-returning function * * @stability stable * @category lifting * @since 2.0.0 */ export declare const liftPredicate: { (refinement: Predicate.Refinement): (a: A) => Array; /** * Lifts a predicate into an array: returns `[value]` if the predicate holds, * `[]` otherwise. * * **Example** (Wrapping values conditionally) * * ```ts import.meta.vitest * import { Array } from "effect" * * const fromEven = Array.liftPredicate((n: number) => n % 2 === 0) * * fromEven(1) // => [] * fromEven(2) // => [2] * ``` * * @see {@link liftOption} — lift an Option-returning function * * @stability stable * @category lifting * @since 2.0.0 */ (predicate: Predicate.Predicate): (b: B) => Array; }; /** * Lifts an `Option`-returning function into one that returns an array: * `Some(a)` becomes `[a]`, `None` becomes `[]`. * * **When to use** * * Use when an optional parser or lookup should participate in array pipelines * as zero-or-one results. * * **Example** (Lifting an Option function) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * const parseNumber = Array.liftOption((s: string) => { * const n = Number(s) * return isNaN(n) ? Option.none() : Option.some(n) * }) * * parseNumber("123") // => [123] * parseNumber("abc") // => [] * ``` * * @see {@link liftPredicate} — lift a boolean predicate * @see {@link liftResult} — lift a Result-returning function * * @stability stable * @category lifting * @since 2.0.0 */ export declare const liftOption: , B>(f: (...a: A) => Option.Option) => (...a: A) => Array; /** * Converts a nullable value to an array: `null`/`undefined` becomes `[]`, * anything else becomes `[value]`. * * **When to use** * * Use to treat a nullable single value as zero or one array element. * * **Example** (Converting nullable values to an array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.fromNullishOr(1) // => [1] * Array.fromNullishOr(null) // => [] * Array.fromNullishOr(undefined) // => [] * ``` * * @see {@link liftNullishOr} — lift a nullable-returning function * @see {@link fromOption} — convert from Option * * @stability stable * @category converting * @since 4.0.0 */ export declare const fromNullishOr: (a: A) => Array>; /** * Lifts a nullable-returning function into one that returns an array: * `null`/`undefined` becomes `[]`, anything else becomes `[value]`. * * **Example** (Lifting a nullable function) * * ```ts import.meta.vitest * import { Array } from "effect" * * const parseNumber = Array.liftNullishOr((s: string) => { * const n = Number(s) * return isNaN(n) ? null : n * }) * * parseNumber("123") // => [123] * parseNumber("abc") // => [] * ``` * * @see {@link fromNullishOr} — convert a single nullable value * @see {@link liftOption} — lift an Option-returning function * * @stability stable * @category lifting * @since 4.0.0 */ export declare const liftNullishOr: , B>(f: (...a: A) => B) => (...a: A) => Array>; /** * Maps each element with a nullable-returning function, keeping only non-null / * non-undefined results. * * **When to use** * * Use when you need to map and filter in one step, where the mapper can return * `null` or `undefined` to skip elements. * * **Example** (Flat mapping with nullable values) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.flatMapNullishOr([1, 2, 3], (n) => (n % 2 === 0 ? null : n)) // => [1, 3] * ``` * * @see {@link flatMap} for mapping each element to an array and flattening * @see {@link fromNullishOr} for converting a single nullable value to an array * * @stability stable * @category sequencing * @since 4.0.0 */ export declare const flatMapNullishOr: { /** * Maps each element with a nullable-returning function, keeping only non-null / * non-undefined results. * * **When to use** * * Use when you need to map and filter in one step, where the mapper can return * `null` or `undefined` to skip elements. * * **Example** (Flat mapping with nullable values) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.flatMapNullishOr([1, 2, 3], (n) => (n % 2 === 0 ? null : n)) // => [1, 3] * ``` * * @see {@link flatMap} for mapping each element to an array and flattening * @see {@link fromNullishOr} for converting a single nullable value to an array * * @stability stable * @category sequencing * @since 4.0.0 */ (f: (a: A) => B): (self: ReadonlyArray) => Array>; /** * Maps each element with a nullable-returning function, keeping only non-null / * non-undefined results. * * **When to use** * * Use when you need to map and filter in one step, where the mapper can return * `null` or `undefined` to skip elements. * * **Example** (Flat mapping with nullable values) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.flatMapNullishOr([1, 2, 3], (n) => (n % 2 === 0 ? null : n)) // => [1, 3] * ``` * * @see {@link flatMap} for mapping each element to an array and flattening * @see {@link fromNullishOr} for converting a single nullable value to an array * * @stability stable * @category sequencing * @since 4.0.0 */ (self: ReadonlyArray, f: (a: A) => B): Array>; }; /** * Lifts a `Result`-returning function into one that returns an array: failures * produce `[]`, successes produce `[value]`. * * **When to use** * * Use when a fallible parser or lookup should participate in array pipelines as * zero-or-one results and the failure value should be discarded. * * **Example** (Lifting a Result function) * * ```ts import.meta.vitest * import { Array, Result } from "effect" * * const parseNumber = (s: string): Result.Result => * isNaN(Number(s)) * ? Result.fail(new Error("Not a number")) * : Result.succeed(Number(s)) * * const liftedParseNumber = Array.liftResult(parseNumber) * * liftedParseNumber("42") // => [42] * liftedParseNumber("not a number") // => [] * ``` * * @see {@link liftOption} — lift an Option-returning function * @see {@link liftPredicate} — lift a boolean predicate * * @stability stable * @category lifting * @since 4.0.0 */ export declare const liftResult: , E, B>(f: (...a: A) => Result.Result) => (...a: A) => Array; /** * Checks whether all elements satisfy the predicate. Supports refinements for * type narrowing. * * **When to use** * * Use to check whether every array element satisfies a predicate, including * refinement-based type narrowing. * * **Example** (Testing all elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.every([2, 4, 6], (x) => x % 2 === 0) // => true * Array.every([2, 3, 6], (x) => x % 2 === 0) // => false * ``` * * @see {@link some} — test if any element matches * * @stability stable * @category guards * @since 2.0.0 */ export declare const every: { /** * Checks whether all elements satisfy the predicate. Supports refinements for * type narrowing. * * **When to use** * * Use to check whether every array element satisfies a predicate, including * refinement-based type narrowing. * * **Example** (Testing all elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.every([2, 4, 6], (x) => x % 2 === 0) // => true * Array.every([2, 3, 6], (x) => x % 2 === 0) // => false * ``` * * @see {@link some} — test if any element matches * * @stability stable * @category guards * @since 2.0.0 */ (refinement: (a: NoInfer, i: number) => a is B): (self: ReadonlyArray) => self is ReadonlyArray; /** * Checks whether all elements satisfy the predicate. Supports refinements for * type narrowing. * * **When to use** * * Use to check whether every array element satisfies a predicate, including * refinement-based type narrowing. * * **Example** (Testing all elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.every([2, 4, 6], (x) => x % 2 === 0) // => true * Array.every([2, 3, 6], (x) => x % 2 === 0) // => false * ``` * * @see {@link some} — test if any element matches * * @stability stable * @category guards * @since 2.0.0 */ (predicate: (a: NoInfer, i: number) => boolean): (self: ReadonlyArray) => boolean; /** * Checks whether all elements satisfy the predicate. Supports refinements for * type narrowing. * * **When to use** * * Use to check whether every array element satisfies a predicate, including * refinement-based type narrowing. * * **Example** (Testing all elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.every([2, 4, 6], (x) => x % 2 === 0) // => true * Array.every([2, 3, 6], (x) => x % 2 === 0) // => false * ``` * * @see {@link some} — test if any element matches * * @stability stable * @category guards * @since 2.0.0 */ (self: ReadonlyArray, refinement: (a: A, i: number) => a is B): self is ReadonlyArray; /** * Checks whether all elements satisfy the predicate. Supports refinements for * type narrowing. * * **When to use** * * Use to check whether every array element satisfies a predicate, including * refinement-based type narrowing. * * **Example** (Testing all elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.every([2, 4, 6], (x) => x % 2 === 0) // => true * Array.every([2, 3, 6], (x) => x % 2 === 0) // => false * ``` * * @see {@link some} — test if any element matches * * @stability stable * @category guards * @since 2.0.0 */ (self: ReadonlyArray, predicate: (a: A, i: number) => boolean): boolean; }; /** * Checks whether at least one element satisfies the predicate. Narrows the type * to `NonEmptyReadonlyArray` on success. * * **Example** (Testing for any match) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.some([1, 3, 4], (x) => x % 2 === 0) // => true * Array.some([1, 3, 5], (x) => x % 2 === 0) // => false * ``` * * @see {@link every} — test if all elements match * @see {@link contains} — test for a specific value * * @stability stable * @category guards * @since 2.0.0 */ export declare const some: { /** * Checks whether at least one element satisfies the predicate. Narrows the type * to `NonEmptyReadonlyArray` on success. * * **Example** (Testing for any match) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.some([1, 3, 4], (x) => x % 2 === 0) // => true * Array.some([1, 3, 5], (x) => x % 2 === 0) // => false * ``` * * @see {@link every} — test if all elements match * @see {@link contains} — test for a specific value * * @stability stable * @category guards * @since 2.0.0 */ (predicate: (a: NoInfer, i: number) => boolean): (self: ReadonlyArray) => self is NonEmptyReadonlyArray; /** * Checks whether at least one element satisfies the predicate. Narrows the type * to `NonEmptyReadonlyArray` on success. * * **Example** (Testing for any match) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.some([1, 3, 4], (x) => x % 2 === 0) // => true * Array.some([1, 3, 5], (x) => x % 2 === 0) // => false * ``` * * @see {@link every} — test if all elements match * @see {@link contains} — test for a specific value * * @stability stable * @category guards * @since 2.0.0 */ (self: ReadonlyArray, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray; }; /** * Applies a function to each suffix of the array (starting from each index), * collecting the results. * * **When to use** * * Use when you need to compute a result from every suffix of an array, such as * cumulative aggregations from each position. * * **Details** * * For index `i`, the function receives `self.slice(i)`. * * **Example** (Computing suffix lengths) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.extend([1, 2, 3], (as) => as.length) // => [3, 2, 1] * ``` * * @see {@link scan} for keeping intermediate accumulator values during a fold * * @stability stable * @category mapping * @since 2.0.0 */ export declare const extend: { /** * Applies a function to each suffix of the array (starting from each index), * collecting the results. * * **When to use** * * Use when you need to compute a result from every suffix of an array, such as * cumulative aggregations from each position. * * **Details** * * For index `i`, the function receives `self.slice(i)`. * * **Example** (Computing suffix lengths) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.extend([1, 2, 3], (as) => as.length) // => [3, 2, 1] * ``` * * @see {@link scan} for keeping intermediate accumulator values during a fold * * @stability stable * @category mapping * @since 2.0.0 */ (f: (as: ReadonlyArray) => B): (self: ReadonlyArray) => Array; /** * Applies a function to each suffix of the array (starting from each index), * collecting the results. * * **When to use** * * Use when you need to compute a result from every suffix of an array, such as * cumulative aggregations from each position. * * **Details** * * For index `i`, the function receives `self.slice(i)`. * * **Example** (Computing suffix lengths) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.extend([1, 2, 3], (as) => as.length) // => [3, 2, 1] * ``` * * @see {@link scan} for keeping intermediate accumulator values during a fold * * @stability stable * @category mapping * @since 2.0.0 */ (self: ReadonlyArray, f: (as: ReadonlyArray) => B): Array; }; /** * Returns the minimum element of a non-empty array according to the given * `Order`. * * **Example** (Finding the minimum) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * Array.min([3, 1, 2], Order.Number) // => 1 * ``` * * @see {@link max} — find the maximum * @see {@link sort} — sort the entire array * * @stability stable * @category getters * @since 2.0.0 */ export declare const min: { /** * Returns the minimum element of a non-empty array according to the given * `Order`. * * **Example** (Finding the minimum) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * Array.min([3, 1, 2], Order.Number) // => 1 * ``` * * @see {@link max} — find the maximum * @see {@link sort} — sort the entire array * * @stability stable * @category getters * @since 2.0.0 */ (O: Order.Order): (self: NonEmptyReadonlyArray) => A; /** * Returns the minimum element of a non-empty array according to the given * `Order`. * * **Example** (Finding the minimum) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * Array.min([3, 1, 2], Order.Number) // => 1 * ``` * * @see {@link max} — find the maximum * @see {@link sort} — sort the entire array * * @stability stable * @category getters * @since 2.0.0 */ (self: NonEmptyReadonlyArray, O: Order.Order): A; }; /** * Returns the maximum element of a non-empty array according to the given * `Order`. * * **Example** (Finding the maximum) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * Array.max([3, 1, 2], Order.Number) // => 3 * ``` * * @see {@link min} — find the minimum * @see {@link sort} — sort the entire array * * @stability stable * @category getters * @since 2.0.0 */ export declare const max: { /** * Returns the maximum element of a non-empty array according to the given * `Order`. * * **Example** (Finding the maximum) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * Array.max([3, 1, 2], Order.Number) // => 3 * ``` * * @see {@link min} — find the minimum * @see {@link sort} — sort the entire array * * @stability stable * @category getters * @since 2.0.0 */ (O: Order.Order): (self: NonEmptyReadonlyArray) => A; /** * Returns the maximum element of a non-empty array according to the given * `Order`. * * **Example** (Finding the maximum) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * Array.max([3, 1, 2], Order.Number) // => 3 * ``` * * @see {@link min} — find the minimum * @see {@link sort} — sort the entire array * * @stability stable * @category getters * @since 2.0.0 */ (self: NonEmptyReadonlyArray, O: Order.Order): A; }; /** * Builds an array by repeatedly applying a function to a seed value. The * function returns `Option.some([element, nextSeed])` to continue, or * `Option.none()` to stop. * * **Example** (Generating a sequence) * * ```ts import.meta.vitest * import { Array, Option } from "effect" * * Array.unfold(1, (n) => n <= 5 ? Option.some([n, n + 1]) : Option.none()) // => [1, 2, 3, 4, 5] * ``` * * @see {@link makeBy} — generate from index * @see {@link range} — generate a numeric range * * @stability stable * @category constructors * @since 2.0.0 */ export declare const unfold: (b: B, f: (b: B) => Option.Option) => Array; /** * Creates an `Order` for arrays based on an element `Order`. Arrays are * compared element-wise; if all compared elements are equal, shorter arrays * come first. * * **Example** (Comparing arrays) * * ```ts import.meta.vitest * import { Array, Order } from "effect" * * const arrayOrder = Array.makeOrder(Order.Number) * * arrayOrder([1, 2], [1, 3]) // => -1 * ``` * * @see {@link makeEquivalence} — create an equivalence for arrays * * @stability stable * @category instances * @since 4.0.0 */ export declare const makeOrder: (O: Order.Order) => Order.Order>; /** * Creates an `Equivalence` for arrays based on an element `Equivalence`. Two * arrays are equivalent when they have the same length and all elements are * pairwise equivalent. * * **Example** (Comparing arrays for equality) * * ```ts import.meta.vitest * import { Array } from "effect" * * const eq = Array.makeEquivalence((a, b) => a === b) * * eq([1, 2, 3], [1, 2, 3]) // => true * ``` * * @see {@link makeOrder} — create an ordering for arrays * * @stability stable * @category instances * @since 4.0.0 */ export declare const makeEquivalence: (isEquivalent: Equivalence.Equivalence) => Equivalence.Equivalence>; /** * Runs a side-effect for each element. The callback receives `(element, index)`. * * **When to use** * * Use to iterate over an array for side-effects only, when no transformed * result is needed. * * **Example** (Iterating with side-effects) * * ```ts import.meta.vitest * import { Array } from "effect" * * const visited: Array = [] * Array.forEach([1, 2, 3], (n) => visited.push(n)) * * visited // => [1, 2, 3] * ``` * * @see {@link map} for transforming each element into a new array * * @stability stable * @category traversing * @since 2.0.0 */ export declare const forEach: { /** * Runs a side-effect for each element. The callback receives `(element, index)`. * * **When to use** * * Use to iterate over an array for side-effects only, when no transformed * result is needed. * * **Example** (Iterating with side-effects) * * ```ts import.meta.vitest * import { Array } from "effect" * * const visited: Array = [] * Array.forEach([1, 2, 3], (n) => visited.push(n)) * * visited // => [1, 2, 3] * ``` * * @see {@link map} for transforming each element into a new array * * @stability stable * @category traversing * @since 2.0.0 */ (f: (a: A, i: number) => void): (self: Iterable) => void; /** * Runs a side-effect for each element. The callback receives `(element, index)`. * * **When to use** * * Use to iterate over an array for side-effects only, when no transformed * result is needed. * * **Example** (Iterating with side-effects) * * ```ts import.meta.vitest * import { Array } from "effect" * * const visited: Array = [] * Array.forEach([1, 2, 3], (n) => visited.push(n)) * * visited // => [1, 2, 3] * ``` * * @see {@link map} for transforming each element into a new array * * @stability stable * @category traversing * @since 2.0.0 */ (self: Iterable, f: (a: A, i: number) => void): void; }; /** * Removes duplicates using a custom equivalence, preserving the order of the * first occurrence. * * **When to use** * * Use to remove all duplicate elements with a custom equivalence when default * equality is not appropriate. * * **Example** (Deduplicating with custom equality) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b) // => [1, 2, 3] * ``` * * @see {@link dedupe} — uses default equality * @see {@link dedupeAdjacentWith} — only dedupes consecutive elements * * @stability stable * @category deduplication * @since 2.0.0 */ export declare const dedupeWith: { /** * Removes duplicates using a custom equivalence, preserving the order of the * first occurrence. * * **When to use** * * Use to remove all duplicate elements with a custom equivalence when default * equality is not appropriate. * * **Example** (Deduplicating with custom equality) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b) // => [1, 2, 3] * ``` * * @see {@link dedupe} — uses default equality * @see {@link dedupeAdjacentWith} — only dedupes consecutive elements * * @stability stable * @category deduplication * @since 2.0.0 */ >(isEquivalent: (self: ReadonlyArray.Infer, that: ReadonlyArray.Infer) => boolean): (self: S) => ReadonlyArray.With>; /** * Removes duplicates using a custom equivalence, preserving the order of the * first occurrence. * * **When to use** * * Use to remove all duplicate elements with a custom equivalence when default * equality is not appropriate. * * **Example** (Deduplicating with custom equality) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b) // => [1, 2, 3] * ``` * * @see {@link dedupe} — uses default equality * @see {@link dedupeAdjacentWith} — only dedupes consecutive elements * * @stability stable * @category deduplication * @since 2.0.0 */ (self: NonEmptyReadonlyArray, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray; /** * Removes duplicates using a custom equivalence, preserving the order of the * first occurrence. * * **When to use** * * Use to remove all duplicate elements with a custom equivalence when default * equality is not appropriate. * * **Example** (Deduplicating with custom equality) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dedupeWith([1, 2, 2, 3, 3, 3], (a, b) => a === b) // => [1, 2, 3] * ``` * * @see {@link dedupe} — uses default equality * @see {@link dedupeAdjacentWith} — only dedupes consecutive elements * * @stability stable * @category deduplication * @since 2.0.0 */ (self: Iterable, isEquivalent: (self: A, that: A) => boolean): Array; }; /** * Removes duplicates using `Equal.asEquivalence()`, preserving the order of the * first occurrence. * * **When to use** * * Use to remove repeated values from an iterable when Effect's default equality * is the right comparison, preserving the first occurrence. * * **Example** (Removing duplicates) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dedupe([1, 2, 1, 3, 2, 4]) // => [1, 2, 3, 4] * ``` * * @see {@link dedupeWith} — use custom equality * @see {@link dedupeAdjacent} — only dedupes consecutive elements * * @stability stable * @category deduplication * @since 2.0.0 */ export declare const dedupe: >(self: S) => S extends NonEmptyReadonlyArray ? NonEmptyArray : S extends Iterable ? Array : never; /** * Removes consecutive duplicate elements using a custom equivalence. * * **When to use** * * Use when consecutive duplicates should be collapsed using a custom * equivalence, while equivalent values that appear later should remain in the * result. * * **Details** * * Non-adjacent duplicates are preserved. * * **Example** (Deduplicating adjacent elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dedupeAdjacentWith([1, 1, 2, 2, 3, 3], (a, b) => a === b) // => [1, 2, 3] * ``` * * @see {@link dedupeAdjacent} — uses default equality * @see {@link dedupeWith} — dedupes all duplicates, not just adjacent * * @stability stable * @category deduplication * @since 2.0.0 */ export declare const dedupeAdjacentWith: { /** * Removes consecutive duplicate elements using a custom equivalence. * * **When to use** * * Use when consecutive duplicates should be collapsed using a custom * equivalence, while equivalent values that appear later should remain in the * result. * * **Details** * * Non-adjacent duplicates are preserved. * * **Example** (Deduplicating adjacent elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dedupeAdjacentWith([1, 1, 2, 2, 3, 3], (a, b) => a === b) // => [1, 2, 3] * ``` * * @see {@link dedupeAdjacent} — uses default equality * @see {@link dedupeWith} — dedupes all duplicates, not just adjacent * * @stability stable * @category deduplication * @since 2.0.0 */ (isEquivalent: (self: A, that: A) => boolean): (self: Iterable) => Array; /** * Removes consecutive duplicate elements using a custom equivalence. * * **When to use** * * Use when consecutive duplicates should be collapsed using a custom * equivalence, while equivalent values that appear later should remain in the * result. * * **Details** * * Non-adjacent duplicates are preserved. * * **Example** (Deduplicating adjacent elements) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dedupeAdjacentWith([1, 1, 2, 2, 3, 3], (a, b) => a === b) // => [1, 2, 3] * ``` * * @see {@link dedupeAdjacent} — uses default equality * @see {@link dedupeWith} — dedupes all duplicates, not just adjacent * * @stability stable * @category deduplication * @since 2.0.0 */ (self: Iterable, isEquivalent: (self: A, that: A) => boolean): Array; }; /** * Removes consecutive duplicate elements using `Equal.asEquivalence()`. * * **When to use** * * Use when you need to collapse consecutive duplicates while preserving later * non-consecutive repeats, and the default equality is sufficient. * * **Example** (Removing adjacent duplicates) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.dedupeAdjacent([1, 1, 2, 2, 3, 3]) // => [1, 2, 3] * ``` * * @see {@link dedupeAdjacentWith} — use custom equality * @see {@link dedupe} — remove all duplicates * * @stability stable * @category deduplication * @since 2.0.0 */ export declare const dedupeAdjacent: (self: Iterable) => Array; /** * Joins string elements with a separator. * * **Example** (Joining strings) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.join(["a", "b", "c"], "-") // => "a-b-c" * ``` * * @see {@link intersperse} — insert separator elements without joining * * @stability stable * @category folding * @since 2.0.0 */ export declare const join: { /** * Joins string elements with a separator. * * **Example** (Joining strings) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.join(["a", "b", "c"], "-") // => "a-b-c" * ``` * * @see {@link intersperse} — insert separator elements without joining * * @stability stable * @category folding * @since 2.0.0 */ (sep: string): (self: Iterable) => string; /** * Joins string elements with a separator. * * **Example** (Joining strings) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.join(["a", "b", "c"], "-") // => "a-b-c" * ``` * * @see {@link intersperse} — insert separator elements without joining * * @stability stable * @category folding * @since 2.0.0 */ (self: Iterable, sep: string): string; }; /** * Maps over an array while threading an accumulator through each step, returning both the final state and the mapped array. * * **When to use** * * Use when you need to map while threading state through each element and keep * the final state. * * **Details** * * Combines `map` and `reduce` in a single pass. The callback receives the * current state, element, and index, and returns `[nextState, mappedValue]`. * The result is `[finalState, mappedArray]`. This can be used in both * data-first and data-last style. * * **Example** (Running sum alongside mapped values) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.mapAccum([1, 2, 3], 0, (acc, n) => [acc + n, acc + n]) // => [6, [1, 3, 6]] * ``` * * @see {@link scan} — when you only need the accumulated results (not the final state) * @see {@link reduce} — when you only need the final accumulated value * * @stability stable * @category folding * @since 2.0.0 */ export declare const mapAccum: { /** * Maps over an array while threading an accumulator through each step, returning both the final state and the mapped array. * * **When to use** * * Use when you need to map while threading state through each element and keep * the final state. * * **Details** * * Combines `map` and `reduce` in a single pass. The callback receives the * current state, element, and index, and returns `[nextState, mappedValue]`. * The result is `[finalState, mappedArray]`. This can be used in both * data-first and data-last style. * * **Example** (Running sum alongside mapped values) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.mapAccum([1, 2, 3], 0, (acc, n) => [acc + n, acc + n]) // => [6, [1, 3, 6]] * ``` * * @see {@link scan} — when you only need the accumulated results (not the final state) * @see {@link reduce} — when you only need the final accumulated value * * @stability stable * @category folding * @since 2.0.0 */ = Iterable>(s: S, f: (s: S, a: ReadonlyArray.Infer, i: number) => readonly [S, B]): (self: I) => [state: S, mappedArray: ReadonlyArray.With]; /** * Maps over an array while threading an accumulator through each step, returning both the final state and the mapped array. * * **When to use** * * Use when you need to map while threading state through each element and keep * the final state. * * **Details** * * Combines `map` and `reduce` in a single pass. The callback receives the * current state, element, and index, and returns `[nextState, mappedValue]`. * The result is `[finalState, mappedArray]`. This can be used in both * data-first and data-last style. * * **Example** (Running sum alongside mapped values) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.mapAccum([1, 2, 3], 0, (acc, n) => [acc + n, acc + n]) // => [6, [1, 3, 6]] * ``` * * @see {@link scan} — when you only need the accumulated results (not the final state) * @see {@link reduce} — when you only need the final accumulated value * * @stability stable * @category folding * @since 2.0.0 */ = Iterable>(self: I, s: S, f: (s: S, a: ReadonlyArray.Infer, i: number) => readonly [S, B]): [state: S, mappedArray: ReadonlyArray.With]; }; /** * Computes the cartesian product of two arrays, applying a combiner to each pair. * * **When to use** * * Use to compute every combination from two arrays and immediately transform * each pair into a custom result. * * **Details** * * Produces every combination of an element from `self` with an element from * `that`, so the result length is `self.length * that.length`. Iteration visits * every element of `that` for each element of `self`. * * **Example** (Combining numbers and letters) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.cartesianWith([1, 2], ["a", "b"], (a, b) => `${a}-${b}`) // => ["1-a", "1-b", "2-a", "2-b"] * ``` * * @see {@link cartesian} for returning tuples instead of applying a combiner * * @stability stable * @category combining * @since 2.0.0 */ export declare const cartesianWith: { /** * Computes the cartesian product of two arrays, applying a combiner to each pair. * * **When to use** * * Use to compute every combination from two arrays and immediately transform * each pair into a custom result. * * **Details** * * Produces every combination of an element from `self` with an element from * `that`, so the result length is `self.length * that.length`. Iteration visits * every element of `that` for each element of `self`. * * **Example** (Combining numbers and letters) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.cartesianWith([1, 2], ["a", "b"], (a, b) => `${a}-${b}`) // => ["1-a", "1-b", "2-a", "2-b"] * ``` * * @see {@link cartesian} for returning tuples instead of applying a combiner * * @stability stable * @category combining * @since 2.0.0 */ (that: ReadonlyArray, f: (a: A, b: B) => C): (self: ReadonlyArray) => Array; /** * Computes the cartesian product of two arrays, applying a combiner to each pair. * * **When to use** * * Use to compute every combination from two arrays and immediately transform * each pair into a custom result. * * **Details** * * Produces every combination of an element from `self` with an element from * `that`, so the result length is `self.length * that.length`. Iteration visits * every element of `that` for each element of `self`. * * **Example** (Combining numbers and letters) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.cartesianWith([1, 2], ["a", "b"], (a, b) => `${a}-${b}`) // => ["1-a", "1-b", "2-a", "2-b"] * ``` * * @see {@link cartesian} for returning tuples instead of applying a combiner * * @stability stable * @category combining * @since 2.0.0 */ (self: ReadonlyArray, that: ReadonlyArray, f: (a: A, b: B) => C): Array; }; /** * Computes the cartesian product of two arrays, returning all pairs as tuples. * * **When to use** * * Use when you need every `[a, b]` pair from two arrays as tuples. * * **Details** * * Produces every `[a, b]` combination of an element from `self` with an element * from `that`, so the result length is `self.length * that.length`. * * **Example** (Generating all pairs from two arrays) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.cartesian([1, 2], ["a", "b"]) // => [[1, "a"], [1, "b"], [2, "a"], [2, "b"]] * ``` * * @see {@link cartesianWith} — apply a combiner to each pair * * @stability stable * @category combining * @since 2.0.0 */ export declare const cartesian: { /** * Computes the cartesian product of two arrays, returning all pairs as tuples. * * **When to use** * * Use when you need every `[a, b]` pair from two arrays as tuples. * * **Details** * * Produces every `[a, b]` combination of an element from `self` with an element * from `that`, so the result length is `self.length * that.length`. * * **Example** (Generating all pairs from two arrays) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.cartesian([1, 2], ["a", "b"]) // => [[1, "a"], [1, "b"], [2, "a"], [2, "b"]] * ``` * * @see {@link cartesianWith} — apply a combiner to each pair * * @stability stable * @category combining * @since 2.0.0 */ (that: ReadonlyArray): (self: ReadonlyArray) => Array<[A, B]>; /** * Computes the cartesian product of two arrays, returning all pairs as tuples. * * **When to use** * * Use when you need every `[a, b]` pair from two arrays as tuples. * * **Details** * * Produces every `[a, b]` combination of an element from `self` with an element * from `that`, so the result length is `self.length * that.length`. * * **Example** (Generating all pairs from two arrays) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.cartesian([1, 2], ["a", "b"]) // => [[1, "a"], [1, "b"], [2, "a"], [2, "b"]] * ``` * * @see {@link cartesianWith} — apply a combiner to each pair * * @stability stable * @category combining * @since 2.0.0 */ (self: ReadonlyArray, that: ReadonlyArray): Array<[A, B]>; }; /** * Provides the starting point for the "do simulation" — an array comprehension pattern. * * **When to use** * * Use when you want array-comprehension style code with do notation. * * **Details** * * Use {@link bind} to introduce array variables and {@link let_ let} for plain * values. Each `bind` produces the cartesian product of all bound variables, * like nested loops. Use `filter` and `map` in the pipeline to add conditions * and transformations. * * **Example** (Building array comprehensions with do notation) * * ```ts import.meta.vitest * import { Array, pipe } from "effect" * * pipe( * Array.Do, * Array.bind("x", () => [1, 3, 5]), * Array.bind("y", () => [2, 4, 6]), * Array.filter(({ x, y }) => x < y), * Array.map(({ x, y }) => [x, y] as const) * ) // => [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]] * ``` * * @see {@link bind} — introduce an array variable into the scope * @see {@link bindTo} — start a pipeline by naming the first array * @see {@link let_ let} — introduce a plain computed value * * @stability stable * @category constructors * @since 3.2.0 */ export declare const Do: ReadonlyArray<{}>; /** * Adds a new array variable to a do-notation scope, producing the cartesian product with all previous bindings. * * **When to use** * * Use to add another array-producing binding to an `Array.Do` pipeline, pairing * each existing scope with every value returned by the callback. * * **Details** * * Each `bind` call adds a named property to the accumulated object. The * callback receives the current scope and must return an array. This is * equivalent to `flatMap` plus merging the new value into the scope object. * * **Example** (Binding two arrays) * * ```ts import.meta.vitest * import { Array, pipe } from "effect" * * pipe( * Array.Do, * Array.bind("x", () => [1, 2]), * Array.bind("y", () => ["a", "b"]) * ) // => [{ x: 1, y: "a" }, { x: 1, y: "b" }, { x: 2, y: "a" }, { x: 2, y: "b" }] * ``` * * @see {@link Do} — start a do-notation pipeline * @see {@link bindTo} — name the first array in a pipeline * @see {@link let_ let} — add a plain computed value * * @stability stable * @category sequencing * @since 3.2.0 */ export declare const bind: { /** * Adds a new array variable to a do-notation scope, producing the cartesian product with all previous bindings. * * **When to use** * * Use to add another array-producing binding to an `Array.Do` pipeline, pairing * each existing scope with every value returned by the callback. * * **Details** * * Each `bind` call adds a named property to the accumulated object. The * callback receives the current scope and must return an array. This is * equivalent to `flatMap` plus merging the new value into the scope object. * * **Example** (Binding two arrays) * * ```ts import.meta.vitest * import { Array, pipe } from "effect" * * pipe( * Array.Do, * Array.bind("x", () => [1, 2]), * Array.bind("y", () => ["a", "b"]) * ) // => [{ x: 1, y: "a" }, { x: 1, y: "b" }, { x: 2, y: "a" }, { x: 2, y: "b" }] * ``` * * @see {@link Do} — start a do-notation pipeline * @see {@link bindTo} — name the first array in a pipeline * @see {@link let_ let} — add a plain computed value * * @stability stable * @category sequencing * @since 3.2.0 */ (tag: Exclude, f: (a: NoInfer) => ReadonlyArray): (self: ReadonlyArray) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>; /** * Adds a new array variable to a do-notation scope, producing the cartesian product with all previous bindings. * * **When to use** * * Use to add another array-producing binding to an `Array.Do` pipeline, pairing * each existing scope with every value returned by the callback. * * **Details** * * Each `bind` call adds a named property to the accumulated object. The * callback receives the current scope and must return an array. This is * equivalent to `flatMap` plus merging the new value into the scope object. * * **Example** (Binding two arrays) * * ```ts import.meta.vitest * import { Array, pipe } from "effect" * * pipe( * Array.Do, * Array.bind("x", () => [1, 2]), * Array.bind("y", () => ["a", "b"]) * ) // => [{ x: 1, y: "a" }, { x: 1, y: "b" }, { x: 2, y: "a" }, { x: 2, y: "b" }] * ``` * * @see {@link Do} — start a do-notation pipeline * @see {@link bindTo} — name the first array in a pipeline * @see {@link let_ let} — add a plain computed value * * @stability stable * @category sequencing * @since 3.2.0 */ (self: ReadonlyArray, tag: Exclude, f: (a: NoInfer) => ReadonlyArray): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>; }; /** * Wraps each array element in an object with the given key, starting a do-notation scope. * * **When to use** * * Use when you already have an array and want to start a do-notation pipeline * by naming each element. * * **Details** * * Equivalent to `Array.map(self, (a) => ({ [tag]: a }))`. This is an * alternative to starting with `Do` plus `bind` when you already have an array. * * **Example** (Naming an existing array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.bindTo([1, 2, 3], "x") // => [{ x: 1 }, { x: 2 }, { x: 3 }] * ``` * * @see {@link Do} — start with an empty scope * @see {@link bind} — add another array variable to the scope * * @stability stable * @category mapping * @since 3.2.0 */ export declare const bindTo: { /** * Wraps each array element in an object with the given key, starting a do-notation scope. * * **When to use** * * Use when you already have an array and want to start a do-notation pipeline * by naming each element. * * **Details** * * Equivalent to `Array.map(self, (a) => ({ [tag]: a }))`. This is an * alternative to starting with `Do` plus `bind` when you already have an array. * * **Example** (Naming an existing array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.bindTo([1, 2, 3], "x") // => [{ x: 1 }, { x: 2 }, { x: 3 }] * ``` * * @see {@link Do} — start with an empty scope * @see {@link bind} — add another array variable to the scope * * @stability stable * @category mapping * @since 3.2.0 */ (tag: N): (self: ReadonlyArray) => Array<{ [K in N]: A; }>; /** * Wraps each array element in an object with the given key, starting a do-notation scope. * * **When to use** * * Use when you already have an array and want to start a do-notation pipeline * by naming each element. * * **Details** * * Equivalent to `Array.map(self, (a) => ({ [tag]: a }))`. This is an * alternative to starting with `Do` plus `bind` when you already have an array. * * **Example** (Naming an existing array) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.bindTo([1, 2, 3], "x") // => [{ x: 1 }, { x: 2 }, { x: 3 }] * ``` * * @see {@link Do} — start with an empty scope * @see {@link bind} — add another array variable to the scope * * @stability stable * @category mapping * @since 3.2.0 */ (self: ReadonlyArray, tag: N): Array<{ [K in N]: A; }>; }; declare const let_: { (tag: Exclude, f: (a: NoInfer) => B): (self: ReadonlyArray) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>; (self: ReadonlyArray, tag: Exclude, f: (a: NoInfer) => B): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>; }; export { /** * Adds a computed plain value to the do-notation scope without introducing a new array dimension. * * **When to use** * * Use when each do-notation branch needs a derived field from the current * bindings without multiplying the number of branches. * * **Details** * * Unlike `bind`, the callback returns a single value instead of an array, so * no cartesian product occurs. Use this for derived or intermediate values * that depend on previously bound variables. * * **Example** (Adding a computed value) * * ```ts import.meta.vitest * import { Array, pipe } from "effect" * * pipe( * Array.Do, * Array.bind("x", () => [1, 2, 3]), * Array.let("doubled", ({ x }) => x * 2) * ) // => [{ x: 1, doubled: 2 }, { x: 2, doubled: 4 }, { x: 3, doubled: 6 }] * ``` * * @see {@link Do} — start a do-notation pipeline * @see {@link bind} — introduce an array variable (produces cartesian product) * * @stability stable * @category mapping * @since 3.2.0 */ let_ as let }; /** * Returns a `Reducer` that combines `ReadonlyArray` values by concatenation. * * @see {@link makeReducerConcat} — mutable `Array` variant * * @stability stable * @category folding * @since 4.0.0 */ export declare function getReadonlyReducerConcat(): Reducer.Reducer>; /** * Returns a `Reducer` that combines `Array` values by concatenation. * * @see {@link getReadonlyReducerConcat} — readonly variant * * @stability stable * @category folding * @since 4.0.0 */ export declare function makeReducerConcat(): Reducer.Reducer>; /** * Computes the number of elements in an iterable that satisfy a predicate. * * **When to use** * * Use when you need to count how many elements of an iterable satisfy a * predicate. * * **Details** * * The predicate receives both the element and its index. Empty iterables return * `0`. * * **Example** (Counting even numbers) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.countBy([1, 2, 3, 4, 5], (n) => n % 2 === 0) // => 2 * ``` * * @see {@link filter} — when you need the matching elements, not just the count * * @stability stable * @category folding * @since 3.16.0 */ export declare const countBy: { /** * Computes the number of elements in an iterable that satisfy a predicate. * * **When to use** * * Use when you need to count how many elements of an iterable satisfy a * predicate. * * **Details** * * The predicate receives both the element and its index. Empty iterables return * `0`. * * **Example** (Counting even numbers) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.countBy([1, 2, 3, 4, 5], (n) => n % 2 === 0) // => 2 * ``` * * @see {@link filter} — when you need the matching elements, not just the count * * @stability stable * @category folding * @since 3.16.0 */ (predicate: (a: NoInfer, i: number) => boolean): (self: Iterable) => number; /** * Computes the number of elements in an iterable that satisfy a predicate. * * **When to use** * * Use when you need to count how many elements of an iterable satisfy a * predicate. * * **Details** * * The predicate receives both the element and its index. Empty iterables return * `0`. * * **Example** (Counting even numbers) * * ```ts import.meta.vitest * import { Array } from "effect" * * Array.countBy([1, 2, 3, 4, 5], (n) => n % 2 === 0) // => 2 * ``` * * @see {@link filter} — when you need the matching elements, not just the count * * @stability stable * @category folding * @since 3.16.0 */ (self: Iterable, predicate: (a: A, i: number) => boolean): number; }; //# sourceMappingURL=Array.d.ts.map