<A>(self: MutableList<A>, value: A): voidRemoves all occurrences of a value from the MutableList using JavaScript
strict equality semantics.
When to use
Use when in-place removal should use JavaScript identity/strict equality rather than Effect structural equality.
Details
The list is modified in place.
Gotchas
Values are compared with !==, so this does not use Effect structural
equality.
Example (Removing matching values)
import { MutableList } from "effect"
const list = MutableList.make<string>()
MutableList.appendAll(list, ["apple", "banana", "apple", "cherry", "apple"])
console.log(list.length) // 5
// Remove all occurrences of "apple"
MutableList.remove(list, "apple")
console.log(MutableList.takeAll(list)) // ["banana", "cherry"]
// Remove non-existent value (no effect)
const colors = MutableList.make<string>()
MutableList.appendAll(colors, ["red", "blue"])
MutableList.remove(colors, "green")
console.log(MutableList.takeAll(colors)) // ["red", "blue"]
// Real-world example: removing completed tasks
const tasks = MutableList.make<{ id: number; status: string }>()
MutableList.appendAll(tasks, [
{ id: 1, status: "pending" },
{ id: 2, status: "completed" },
{ id: 3, status: "pending" },
{ id: 4, status: "completed" }
])
// Remove completed tasks by filtering status
MutableList.filter(tasks, (task) => task.status !== "completed")
console.log(MutableList.takeAll(tasks).map((task) => task.id)) // [1, 3]export const const remove: <A>(
self: MutableList<A>,
value: A
) => void
Removes all occurrences of a value from the MutableList using JavaScript
strict equality semantics.
When to use
Use when in-place removal should use JavaScript identity/strict equality
rather than Effect structural equality.
Details
The list is modified in place.
Gotchas
Values are compared with !==, so this does not use Effect structural
equality.
Example (Removing matching values)
import { MutableList } from "effect"
const list = MutableList.make<string>()
MutableList.appendAll(list, ["apple", "banana", "apple", "cherry", "apple"])
console.log(list.length) // 5
// Remove all occurrences of "apple"
MutableList.remove(list, "apple")
console.log(MutableList.takeAll(list)) // ["banana", "cherry"]
// Remove non-existent value (no effect)
const colors = MutableList.make<string>()
MutableList.appendAll(colors, ["red", "blue"])
MutableList.remove(colors, "green")
console.log(MutableList.takeAll(colors)) // ["red", "blue"]
// Real-world example: removing completed tasks
const tasks = MutableList.make<{ id: number; status: string }>()
MutableList.appendAll(tasks, [
{ id: 1, status: "pending" },
{ id: 2, status: "completed" },
{ id: 3, status: "pending" },
{ id: 4, status: "completed" }
])
// Remove completed tasks by filtering status
MutableList.filter(tasks, (task) => task.status !== "completed")
console.log(MutableList.takeAll(tasks).map((task) => task.id)) // [1, 3]
remove = <function (type parameter) A in <A>(self: MutableList<A>, value: 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>, value: A): voidA>, value: Avalue: function (type parameter) A in <A>(self: MutableList<A>, value: A): voidA): void => const filter: <A>(
self: MutableList<A>,
f: (value: A, i: number) => boolean
) => void
Filters the MutableList in place, keeping only elements that satisfy the predicate.
This operation modifies the list and rebuilds its internal structure for efficiency.
Example (Filtering in place)
import { MutableList } from "effect"
const list = MutableList.make<number>()
MutableList.appendAll(list, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
console.log(list.length) // 10
// Keep only even numbers
MutableList.filter(list, (n) => n % 2 === 0)
console.log(MutableList.takeAll(list)) // [2, 4, 6, 8, 10]
// Filter with index
const indexed = MutableList.make<string>()
MutableList.appendAll(indexed, ["a", "b", "c", "d", "e"])
// Keep elements at even indices
MutableList.filter(indexed, (value, index) => index % 2 === 0)
console.log(MutableList.takeAll(indexed)) // ["a", "c", "e"]
// Real-world example: filtering a log queue
const logs = MutableList.make<{ level: string; message: string }>()
MutableList.appendAll(logs, [
{ level: "INFO", message: "App started" },
{ level: "ERROR", message: "Connection failed" },
{ level: "DEBUG", message: "Cache hit" },
{ level: "ERROR", message: "Timeout" }
])
// Keep only errors
MutableList.filter(logs, (log) => log.level === "ERROR")
console.log(MutableList.takeAll(logs).map((log) => log.message)) // ["Connection failed", "Timeout"]
filter(self: MutableList<A>(parameter) self: {
head: MutableList.Bucket<A> | undefined;
tail: MutableList.Bucket<A> | undefined;
length: number;
}
self, (v: Av) => v: Av !== value: Avalue)