effect-io-ai

Package: effect
Module: Chunk

Chunk.prepend

Prepends an element to the front of a Chunk, creating a new NonEmptyChunk.

Example (Prepending an element)

import { Chunk } from "effect"

const chunk = Chunk.make(2, 3, 4)
const newChunk = Chunk.prepend(chunk, 1)
console.log(Chunk.toArray(newChunk)) // [1, 2, 3, 4]

// Prepending to empty chunk
const emptyChunk = Chunk.empty<string>()
const singleElement = Chunk.prepend(emptyChunk, "first")
console.log(Chunk.toArray(singleElement)) // ["first"]

Signature

declare const prepend: { <B>(elem: B): <A>(self: Chunk<A>) => NonEmptyChunk<B | A>; <A, B>(self: Chunk<A>, elem: B): NonEmptyChunk<A | B>; }

Source

Since v2.0.0