effect-io-ai

Package: effect
Module: Array

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

import { Array } from "effect"

console.log(Array.modifyLastNonEmpty([1, 2, 3], (n) => n * 2)) // [1, 2, 6]

See

Signature

declare const modifyLastNonEmpty: { <A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>; <A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>; }

Source

Since v4.0.0