Hyperlinkv0.8.0-beta.28

MutableList

MutableList.prependconsteffect/MutableList.ts:342
<A>(self: MutableList<A>, message: A): void

Prepends an element to the beginning of the MutableList. This operation is optimized for high-frequency usage.

Example (Prepending elements)

import { MutableList } from "effect"

const list = MutableList.make<string>()

// Prepend elements (they'll be at the front)
MutableList.prepend(list, "third")
MutableList.prepend(list, "second")
MutableList.prepend(list, "first")

console.log(list.length) // 3

// Elements taken from head (most recently prepended first)
console.log(MutableList.take(list)) // "first"
console.log(MutableList.take(list)) // "second"
console.log(MutableList.take(list)) // "third"

// Use case: priority items or stack-like behavior
MutableList.append(list, "normal")
MutableList.prepend(list, "priority") // This will be taken first
console.log(MutableList.take(list)) // "priority"
mutations
export const prepend = <A>(self: MutableList<A>, message: A): void => {
  self.head = {
    array: [message],
    mutable: true,
    offset: 0,
    next: self.head
  }
  self.length++
}
Referenced by 1 symbols