Package: effect
Module: Array
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)
import { Array } from "effect"
console.log(Array.insertAt(["a", "b", "c", "e"], 3, "d")) // Option.some(["a", "b", "c", "d", "e"])
See
replace — replace an existing elementmodify — transform an element at an indexSignature
declare const insertAt: { <B>(i: number, b: B): <A>(self: Iterable<A>) => Option.Option<NonEmptyArray<A | B>>; <A, B>(self: Iterable<A>, i: number, b: B): Option.Option<NonEmptyArray<A | B>>; }
Since v2.0.0