Hyperlinkv0.8.0-beta.28

MutableList

MutableList.clearconsteffect/MutableList.ts:572
<A>(self: MutableList<A>): void

Removes all elements from the MutableList, resetting it to an empty state. This operation is highly optimized and releases all internal memory.

Example (Clearing a mutable list)

import { MutableList } from "effect"

const list = MutableList.make<number>()
MutableList.appendAll(list, [1, 2, 3, 4, 5])

console.log(list.length) // 5

// Clear all elements
MutableList.clear(list)

console.log(list.length) // 0
console.log(MutableList.take(list)) // Empty

// Can still use the list after clearing
MutableList.append(list, 42)
console.log(list.length) // 1

// Useful for resetting queues or buffers
function resetBuffer<T>(buffer: MutableList.MutableList<T>) {
  MutableList.clear(buffer)
  console.log("Buffer cleared and ready for reuse")
}
mutations
export const clear = <A>(self: MutableList<A>): void => {
  self.head = self.tail = undefined
  self.length = 0
}
Referenced by 4 symbols