Hyperlinkv0.8.0-beta.28

MutableList

MutableList.takeAllconsteffect/MutableList.ts:735
<A>(self: MutableList<A>): Array<A>

Takes all elements from the MutableList and returns them as an array. The list becomes empty after this operation. This is equivalent to takeN(list, list.length).

Example (Draining all elements)

import { MutableList } from "effect"

const list = MutableList.make<string>()
MutableList.appendAll(list, ["apple", "banana", "cherry"])

console.log(list.length) // 3

// Take all elements
const allItems = MutableList.takeAll(list)
console.log(allItems) // ["apple", "banana", "cherry"]
console.log(list.length) // 0

// Useful for converting to array and clearing
const queue = MutableList.make<number>()
MutableList.appendAll(queue, [1, 2, 3, 4, 5])

const snapshot = MutableList.takeAll(queue)
console.log("Queue contents:", snapshot)
console.log("Queue is now empty:", queue.length === 0)

// Drain pattern for processing
function drainAndProcess<T>(
  list: MutableList.MutableList<T>,
  processor: (items: Array<T>) => void
) {
  if (list.length > 0) {
    const items = MutableList.takeAll(list)
    processor(items)
  }
}
elements
export const takeAll = <A>(self: MutableList<A>): Array<A> => takeN(self, self.length)
Referenced by 3 symbols