Hyperlinkv0.8.0-beta.28

Array

Array.prependconsteffect/Array.ts:578
<B>(head: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>
<A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B>

Adds a single element to the front of an iterable, returning a NonEmptyArray.

When to use

Use when you need to guarantee a non-empty result after adding a required leading value.

Example (Prepending an element)

import { Array } from "effect"

const result = Array.prepend([2, 3, 4], 1)
console.log(result) // [1, 2, 3, 4]
Source effect/Array.ts:5784 lines
export const prepend: {
  <B>(head: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>
  <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B>
} = dual(2, <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B> => [head, ...self])
Referenced by 1 symbols