effect-io-ai

Package: effect
Module: Array

Array.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)

import { Array } from "effect"

console.log(Array.replace([1, 2, 3], 1, 4)) // Option.some([1, 4, 3])

See

Signature

declare const replace: { <B>(i: number, b: B): <A, S extends Iterable<A> = Iterable<A>>(self: S) => Option.Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>; <A, B, S extends Iterable<A> = Iterable<A>>(self: S, i: number, b: B): Option.Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>; }

Source

Since v2.0.0