<A>(): MutableList<A>Creates an empty MutableList.
Example (Creating an empty mutable list)
import { MutableList } from "effect"
const list = MutableList.make<string>()
// Add elements
MutableList.append(list, "first")
MutableList.append(list, "second")
MutableList.prepend(list, "beginning")
console.log(list.length) // 3
// Take elements in FIFO order (from head)
console.log(MutableList.take(list)) // "beginning"
console.log(MutableList.take(list)) // "first"
console.log(MutableList.take(list)) // "second"constructors
Source effect/MutableList.ts:2545 lines
export const const make: <A>() => MutableList<A>Creates an empty MutableList.
Example (Creating an empty mutable list)
import { MutableList } from "effect"
const list = MutableList.make<string>()
// Add elements
MutableList.append(list, "first")
MutableList.append(list, "second")
MutableList.prepend(list, "beginning")
console.log(list.length) // 3
// Take elements in FIFO order (from head)
console.log(MutableList.take(list)) // "beginning"
console.log(MutableList.take(list)) // "first"
console.log(MutableList.take(list)) // "second"
make = <function (type parameter) A in <A>(): MutableList<A>A>(): interface MutableList<in out A>A mutable linked list data structure optimized for high-throughput operations.
MutableList provides efficient append/prepend operations and is ideal for
producer-consumer patterns, queues, and streaming scenarios.
Example (Creating and consuming a mutable list)
import { MutableList } from "effect"
// Create a mutable list
const list: MutableList.MutableList<number> = MutableList.make()
// Add elements
MutableList.append(list, 1)
MutableList.append(list, 2)
MutableList.prepend(list, 0)
// Access properties
console.log(list.length) // 3
console.log(list.head?.array) // Contains elements from head bucket
console.log(list.tail?.array) // Contains elements from tail bucket
// Take elements
console.log(MutableList.take(list)) // 0
console.log(MutableList.take(list)) // 1
console.log(MutableList.take(list)) // 2
The MutableList namespace contains type definitions and utilities for working
with mutable linked lists.
Example (Typing queue processors)
import { MutableList } from "effect"
// Type annotation using the namespace
const processQueue = (queue: MutableList.MutableList<string>) => {
while (queue.length > 0) {
const item = MutableList.take(queue)
if (item !== MutableList.Empty) {
console.log("Processing:", item)
}
}
}
// Using the namespace for type definitions
const createProcessor = <T>(): {
queue: MutableList.MutableList<T>
add: (item: T) => void
process: () => Array<T>
} => {
const queue = MutableList.make<T>()
return {
queue,
add: (item) => MutableList.append(queue, item),
process: () => MutableList.takeAll(queue)
}
}
MutableList<function (type parameter) A in <A>(): MutableList<A>A> => ({
MutableList<A>.head: MutableList.Bucket<A> | undefinedhead: var undefinedundefined,
MutableList<A>.tail: MutableList.Bucket<A> | undefinedtail: var undefinedundefined,
MutableList<in out A>.length: numberlength: 0
})Referenced by 5 symbols