Hyperlinkv0.8.0-beta.28

MutableList

MutableList.appendAllUnsafeconsteffect/MutableList.ts:519
<A>(
  self: MutableList<A>,
  messages: ReadonlyArray<A>,
  mutable?: boolean
): number

Appends all elements from a ReadonlyArray to the end of the MutableList. This is an optimized version that can reuse the array when mutable=true. Returns the number of elements added.

When to use

Use when appending 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 (Appending arrays with optional mutation)

import { MutableList } from "effect"

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

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

// Unsafe but efficient usage (mutable=true)
const mutableItems = [5, 6, 7]
MutableList.appendAllUnsafe(list, mutableItems, true)
// mutableItems may be modified internally for efficiency

console.log(MutableList.takeAll(list)) // [1, 2, 3, 4, 5, 6, 7]

// High-performance bulk operations
const bigArray = new Array(10000).fill(0).map((_, i) => i)
MutableList.appendAllUnsafe(list, bigArray, true) // Very efficient
mutations
export const appendAllUnsafe = <A>(self: MutableList<A>, messages: ReadonlyArray<A>, mutable = false): number => {
  if (messages.length === 0) {
    return 0
  }
  const chunk: MutableList.Bucket<A> = {
    array: messages as Array<A>,
    mutable,
    offset: 0,
    next: undefined
  }
  if (self.head) {
    self.tail = self.tail!.next = chunk
  } else {
    self.head = self.tail = chunk
  }
  self.length += messages.length
  return messages.length
}
Referenced by 3 symbols