<A>(self: MutableList<A>, messages: Iterable<A>): voidPrepends all elements from an iterable to the beginning of the MutableList. The elements are added in order, so the first element in the iterable becomes the new head of the list.
Example (Prepending multiple elements)
import { MutableList } from "effect"
const list = MutableList.make<number>()
MutableList.append(list, 4)
MutableList.append(list, 5)
// Prepend multiple elements
MutableList.prependAll(list, [1, 2, 3])
console.log(list.length) // 5
// Elements are taken in order: [1, 2, 3, 4, 5]
console.log(MutableList.takeAll(list)) // [1, 2, 3, 4, 5]
// Works with any iterable
const newList = MutableList.make<string>()
MutableList.prependAll(newList, "hello") // Prepends each character
console.log(MutableList.takeAll(newList)) // ["h", "e", "l", "l", "o"]export const const prependAll: <A>(
self: MutableList<A>,
messages: Iterable<A>
) => void
Prepends all elements from an iterable to the beginning of the MutableList.
The elements are added in order, so the first element in the iterable becomes
the new head of the list.
Example (Prepending multiple elements)
import { MutableList } from "effect"
const list = MutableList.make<number>()
MutableList.append(list, 4)
MutableList.append(list, 5)
// Prepend multiple elements
MutableList.prependAll(list, [1, 2, 3])
console.log(list.length) // 5
// Elements are taken in order: [1, 2, 3, 4, 5]
console.log(MutableList.takeAll(list)) // [1, 2, 3, 4, 5]
// Works with any iterable
const newList = MutableList.make<string>()
MutableList.prependAll(newList, "hello") // Prepends each character
console.log(MutableList.takeAll(newList)) // ["h", "e", "l", "l", "o"]
prependAll = <function (type parameter) A in <A>(self: MutableList<A>, messages: Iterable<A>): voidA>(self: MutableList<A>(parameter) self: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
self: 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>(self: MutableList<A>, messages: Iterable<A>): voidA>, messages: Iterable<A>messages: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: MutableList<A>, messages: Iterable<A>): voidA>): void =>
const prependAllUnsafe: <A>(
self: MutableList<A>,
messages: ReadonlyArray<A>,
mutable?: boolean
) => void
Prepends all elements from a ReadonlyArray to the beginning of the MutableList.
This is an optimized version that can reuse the array when mutable=true.
When to use
Use when prepending a trusted array directly is worth the optimized path and
you control whether the input may be reused.
Gotchas
When mutable=true, the input array may be modified internally. Only use
mutable=true when you control the array lifecycle.
Example (Prepending arrays with optional mutation)
import { MutableList } from "effect"
const list = MutableList.make<number>()
MutableList.append(list, 4)
// Safe usage (default mutable=false)
const items = [1, 2, 3]
MutableList.prependAllUnsafe(list, items)
console.log(items) // [1, 2, 3] - unchanged
// Unsafe but efficient usage (mutable=true)
const mutableItems = [10, 20, 30]
MutableList.prependAllUnsafe(list, mutableItems, true)
// mutableItems may be modified internally for efficiency
console.log(MutableList.takeAll(list)) // [10, 20, 30, 1, 2, 3, 4]
prependAllUnsafe(self: MutableList<A>(parameter) self: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
self, import ArrArr.fromIterable(messages: Iterable<A>messages), !var Array: ArrayConstructorArray.ArrayConstructor.isArray(arg: any): arg is any[]isArray(messages: Iterable<A>messages))