Hyperlinkv0.8.0-beta.28

Array

Array.setLastNonEmptyconsteffect/Array.ts:2457
<B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>
<A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>

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)

import { Array } from "effect"

console.log(Array.setLastNonEmpty([1, 2, 3], 4)) // [1, 2, 4]
Source effect/Array.ts:24577 lines
export const setLastNonEmpty: {
  <B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>
  <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>
} = dual(
  2,
  <A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyLastNonEmpty(self, () => b)
)