Hyperlinkv0.8.0-beta.28

MutableList

MutableList.prependAllUnsafeconsteffect/MutableList.ts:424
<A>(
  self: MutableList<A>,
  messages: ReadonlyArray<A>,
  mutable?: boolean
): void

Prepends all elements from a ReadonlyArray to the beginning of the MutableList. This is an optimized version that can reuse the array when mutable=true.

When to use

Use when prepending a trusted array directly is worth the optimized path and you control whether the input may be reused.

Gotchas

When mutable=true, the input array may be modified internally. Only use mutable=true when you control the array lifecycle.

Example (Prepending arrays with optional mutation)

import { MutableList } from "effect"

const list = MutableList.make<number>()
MutableList.append(list, 4)

// Safe usage (default mutable=false)
const items = [1, 2, 3]
MutableList.prependAllUnsafe(list, items)
console.log(items) // [1, 2, 3] - unchanged

// Unsafe but efficient usage (mutable=true)
const mutableItems = [10, 20, 30]
MutableList.prependAllUnsafe(list, mutableItems, true)
// mutableItems may be modified internally for efficiency

console.log(MutableList.takeAll(list)) // [10, 20, 30, 1, 2, 3, 4]
mutations
export const prependAllUnsafe = <A>(self: MutableList<A>, messages: ReadonlyArray<A>, mutable = false): void => {
  self.head = {
    array: messages as Array<A>,
    mutable,
    offset: 0,
    next: self.head
  }
  self.length += self.head.array.length
}
Referenced by 1 symbols