<A>(self: MutableList<A>, message: A): voidAppends an element to the end of the MutableList. This operation is optimized for high-frequency usage.
Example (Appending elements)
import { MutableList } from "effect"
const list = MutableList.make<number>()
// Append elements one by one
MutableList.append(list, 1)
MutableList.append(list, 2)
MutableList.append(list, 3)
console.log(list.length) // 3
// Elements are taken from head (FIFO)
console.log(MutableList.take(list)) // 1
console.log(MutableList.take(list)) // 2
console.log(MutableList.take(list)) // 3
// High-throughput usage
for (let i = 0; i < 10000; i++) {
MutableList.append(list, i)
}mutations
Source effect/MutableList.ts:29910 lines
export const const append: <A>(
self: MutableList<A>,
message: A
) => void
Appends an element to the end of the MutableList.
This operation is optimized for high-frequency usage.
Example (Appending elements)
import { MutableList } from "effect"
const list = MutableList.make<number>()
// Append elements one by one
MutableList.append(list, 1)
MutableList.append(list, 2)
MutableList.append(list, 3)
console.log(list.length) // 3
// Elements are taken from head (FIFO)
console.log(MutableList.take(list)) // 1
console.log(MutableList.take(list)) // 2
console.log(MutableList.take(list)) // 3
// High-throughput usage
for (let i = 0; i < 10000; i++) {
MutableList.append(list, i)
}
append = <function (type parameter) A in <A>(self: MutableList<A>, message: 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>, message: A): voidA>, message: Amessage: function (type parameter) A in <A>(self: MutableList<A>, message: A): voidA): void => {
if (!self: MutableList<A>(parameter) self: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
self.MutableList<A>.tail: MutableList.Bucket<A> | undefinedtail) {
self: MutableList<A>(parameter) self: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
self.MutableList<A>.head: MutableList.Bucket<A> | undefinedhead = self: MutableList<A>(parameter) self: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
self.MutableList<A>.tail: MutableList.Bucket<A> | undefinedtail = const emptyBucket: <A>() => MutableList<in out A>.Bucket<A>emptyBucket()
} else if (!self: MutableList<A>(parameter) self: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
self.MutableList<A>.tail: MutableList.Bucket<A>(property) MutableList<A>.tail: {
array: Array<A>;
mutable: boolean;
offset: number;
next: Bucket<A> | undefined;
}
tail.MutableList<in out A>.Bucket<A>.mutable: booleanmutable) {
self: MutableList<A>(parameter) self: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
self.MutableList<A>.tail: MutableList.Bucket<A>(property) MutableList<A>.tail: {
array: Array<A>;
mutable: boolean;
offset: number;
next: Bucket<A> | undefined;
}
tail.MutableList<in out A>.Bucket<A>.next: MutableList.Bucket<A> | undefinednext = const emptyBucket: <A>() => MutableList<in out A>.Bucket<A>emptyBucket()
self: MutableList<A>(parameter) self: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
self.MutableList<A>.tail: MutableList.Bucket<A> | undefinedtail = self: MutableList<A>(parameter) self: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
self.MutableList<A>.tail: MutableList.Bucket<A>(property) MutableList<A>.tail: {
array: Array<A>;
mutable: boolean;
offset: number;
next: Bucket<A> | undefined;
}
tail.MutableList<in out A>.Bucket<A>.next: MutableList.Bucket<A>(property) MutableList<in out A>.Bucket<A>.next: {
array: Array<A>;
mutable: boolean;
offset: number;
next: Bucket<A> | undefined;
}
next
}
self: MutableList<A>(parameter) self: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
self.MutableList<A>.tail: MutableList.Bucket<A>(property) MutableList<A>.tail: {
array: Array<A>;
mutable: boolean;
offset: number;
next: Bucket<A> | undefined;
}
tail!.MutableList<in out A>.Bucket<A>.array: A[]array.Array<A>.push(...items: A[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(message: Amessage)
self: MutableList<A>(parameter) self: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
self.MutableList<in out A>.length: numberlength++
}Referenced by 4 symbols