effect-io-ai

Package: effect
Module: MutableList

MutableList.clear

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")
}

Signature

declare const clear: <A>(self: MutableList<A>) => void

Source

Since v4.0.0