Hyperlinkv0.8.0-beta.28

Array

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

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)

import { Array } from "effect"

console.log(Array.setHeadNonEmpty([1, 2, 3], 10)) // [10, 2, 3]
Source effect/Array.ts:23957 lines
export const setHeadNonEmpty: {
  <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> => modifyHeadNonEmpty(self, () => b)
)