<K, A = unknown, E = unknown>(): Effect.Effect<
FiberMap<K, A, E>,
never,
Scope.Scope
>Creates a scoped FiberMap for storing fibers by key.
Details
When the associated Scope is closed, all fibers in the map will be
interrupted. You can add fibers to the map using FiberMap.set or
FiberMap.run, and the fibers will be automatically removed from the
FiberMap when they complete.
Example (Creating a scoped FiberMap)
import { Effect, FiberMap } from "effect"
Effect.gen(function*() {
const map = yield* FiberMap.make<string>()
// run some effects and add the fibers to the map
yield* FiberMap.run(map, "fiber a", Effect.never)
yield* FiberMap.run(map, "fiber b", Effect.never)
yield* Effect.sleep(1000)
}).pipe(
Effect.scoped // The fibers will be interrupted when the scope is closed
)export const const make: <
K,
A = unknown,
E = unknown
>() => Effect.Effect<
FiberMap<K, A, E>,
never,
Scope.Scope
>
Creates a scoped FiberMap for storing fibers by key.
Details
When the associated Scope is closed, all fibers in the map will be
interrupted. You can add fibers to the map using FiberMap.set or
FiberMap.run, and the fibers will be automatically removed from the
FiberMap when they complete.
Example (Creating a scoped FiberMap)
import { Effect, FiberMap } from "effect"
Effect.gen(function*() {
const map = yield* FiberMap.make<string>()
// run some effects and add the fibers to the map
yield* FiberMap.run(map, "fiber a", Effect.never)
yield* FiberMap.run(map, "fiber b", Effect.never)
yield* Effect.sleep(1000)
}).pipe(
Effect.scoped // The fibers will be interrupted when the scope is closed
)
make = <function (type parameter) K in <K, A = unknown, E = unknown>(): Effect.Effect<FiberMap<K, A, E>, never, Scope.Scope>K, function (type parameter) A in <K, A = unknown, E = unknown>(): Effect.Effect<FiberMap<K, A, E>, never, Scope.Scope>A = unknown, function (type parameter) E in <K, A = unknown, E = unknown>(): Effect.Effect<FiberMap<K, A, E>, never, Scope.Scope>E = unknown>(): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<interface FiberMap<in out K, out A = unknown, out E = unknown>A FiberMap is a collection of fibers, indexed by a key. When the associated
Scope is closed, all fibers in the map will be interrupted. Fibers are
automatically removed from the map when they complete.
Example (Managing fibers in a map)
import { Effect, FiberMap } from "effect"
// Create a FiberMap with string keys
const program = Effect.gen(function*() {
const map = yield* FiberMap.make<string>()
// Add some fibers to the map
yield* FiberMap.run(map, "task1", Effect.never)
yield* FiberMap.run(map, "task2", Effect.never)
// Get the size of the map
const size = yield* FiberMap.size(map)
console.log(size) // 2
})
FiberMap<function (type parameter) K in <K, A = unknown, E = unknown>(): Effect.Effect<FiberMap<K, A, E>, never, Scope.Scope>K, function (type parameter) A in <K, A = unknown, E = unknown>(): Effect.Effect<FiberMap<K, A, E>, never, Scope.Scope>A, function (type parameter) E in <K, A = unknown, E = unknown>(): Effect.Effect<FiberMap<K, A, E>, never, Scope.Scope>E>, never, import ScopeScope.Scope> =>
import EffectEffect.acquireRelease(
import EffectEffect.sync(() =>
const makeUnsafe: <
K,
A = unknown,
E = unknown
>(
backing: MutableHashMap.MutableHashMap<
K,
Fiber.Fiber<A, E>
>,
deferred: Deferred.Deferred<void, E>
) => FiberMap<K, A, E>
makeUnsafe<function (type parameter) K in <K, A = unknown, E = unknown>(): Effect.Effect<FiberMap<K, A, E>, never, Scope.Scope>K, function (type parameter) A in <K, A = unknown, E = unknown>(): Effect.Effect<FiberMap<K, A, E>, never, Scope.Scope>A, function (type parameter) E in <K, A = unknown, E = unknown>(): Effect.Effect<FiberMap<K, A, E>, never, Scope.Scope>E>(
import MutableHashMapMutableHashMap.const empty: <K, V>() => MutableHashMap<
K,
V
>
Creates an empty MutableHashMap.
When to use
Use to create a fresh mutable map before adding entries over time.
Details
Each call returns a new empty map instance.
Example (Creating an empty map)
import { MutableHashMap } from "effect"
const map = MutableHashMap.empty<string, number>()
// Add some entries
MutableHashMap.set(map, "key1", 42)
MutableHashMap.set(map, "key2", 100)
console.log(MutableHashMap.size(map)) // 2
empty(),
import DeferredDeferred.makeUnsafe()
)
),
(map: FiberMap<K, A, E>(parameter) map: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; readonly backing: MutableHashMap.MutableHashMap<K, Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" };
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
map) =>
import EffectEffect.suspend(() => {
const const state: anystate = map: FiberMap<K, A, E>(parameter) map: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; readonly backing: MutableHashMap.MutableHashMap<K, Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" };
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
map.state
if (const state: anystate._tag === "Closed") return import EffectEffect.void
map: FiberMap<K, A, E>(parameter) map: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; readonly backing: MutableHashMap.MutableHashMap<K, Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" };
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
map.state = { _tag: string_tag: "Closed" }
return import FiberFiber.interruptAll(import MutableHashMapMutableHashMap.const values: <K, V>(
self: MutableHashMap<K, V>
) => Iterable<V>
Returns an iterable over the values in the MutableHashMap.
When to use
Use to iterate over the values currently stored in a mutable hash map.
Example (Reading values)
import { MutableHashMap } from "effect"
const map = MutableHashMap.make(
["apple", 1],
["banana", 2],
["cherry", 3]
)
const allValues = Array.from(MutableHashMap.values(map))
console.log(allValues) // [1, 2, 3]
// Useful for calculations
const total = allValues.reduce((sum, value) => sum + value, 0)
console.log(total) // 6
// Filter values
const largeValues = allValues.filter((value) => value > 1)
console.log(largeValues) // [2, 3]
values(const state: anyconst state: {
_tag: "Open";
backing: MutableHashMap.MutableHashMap<K, Fiber.Fiber<A, E>>;
}
state.backing)).pipe(
import DeferredDeferred.into(map: FiberMap<K, A, E>(parameter) map: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; readonly backing: MutableHashMap.MutableHashMap<K, Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" };
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
map.deferred)
)
})
)