Hyperlinkv0.8.0-beta.28

MutableList

MutableList.appendAllconsteffect/MutableList.ts:472
<A>(self: MutableList<A>, messages: Iterable<A>): number

Appends all elements from an iterable to the end of the MutableList. Returns the number of elements added.

Example (Appending multiple elements)

import { MutableList } from "effect"

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

// Append multiple elements
const added = MutableList.appendAll(list, [3, 4, 5])
console.log(added) // 3
console.log(list.length) // 5

// Elements maintain order: [1, 2, 3, 4, 5]
console.log(MutableList.takeAll(list)) // [1, 2, 3, 4, 5]

// Works with any iterable
const newList = MutableList.make<string>()
MutableList.appendAll(newList, new Set(["a", "b", "c"]))
console.log(MutableList.takeAll(newList)) // ["a", "b", "c"]

// Useful for bulk loading
const bulkList = MutableList.make<number>()
const count = MutableList.appendAll(
  bulkList,
  Array.from({ length: 1000 }, (_, i) => i)
)
console.log(count) // 1000
mutations
export const appendAll = <A>(self: MutableList<A>, messages: Iterable<A>): number =>
  appendAllUnsafe(self, Arr.fromIterable(messages), !Array.isArray(messages))
Referenced by 2 symbols