Hyperlinkv0.8.0-beta.28

MutableList

MutableList.appendconsteffect/MutableList.ts:299
<A>(self: MutableList<A>, message: A): void

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

Example (Appending elements)

import { MutableList } from "effect"

const list = MutableList.make<number>()

// Append elements one by one
MutableList.append(list, 1)
MutableList.append(list, 2)
MutableList.append(list, 3)

console.log(list.length) // 3

// Elements are taken from head (FIFO)
console.log(MutableList.take(list)) // 1
console.log(MutableList.take(list)) // 2
console.log(MutableList.take(list)) // 3

// High-throughput usage
for (let i = 0; i < 10000; i++) {
  MutableList.append(list, i)
}
mutations
export const append = <A>(self: MutableList<A>, message: A): void => {
  if (!self.tail) {
    self.head = self.tail = emptyBucket()
  } else if (!self.tail.mutable) {
    self.tail.next = emptyBucket()
    self.tail = self.tail.next
  }
  self.tail!.array.push(message)
  self.length++
}
Referenced by 4 symbols