<K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<void>
<K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>Removes a fiber from the FiberMap, interrupting it if it exists.
Example (Removing a fiber)
import { Effect, FiberMap } from "effect"
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)
console.log(yield* FiberMap.size(map)) // 2
// Remove a specific fiber (this will interrupt it)
yield* FiberMap.remove(map, "task1")
console.log(yield* FiberMap.size(map)) // 1
})export const const remove: {
<K>(key: K): <A, E>(
self: FiberMap<K, A, E>
) => Effect.Effect<void>
<K, A, E>(
self: FiberMap<K, A, E>,
key: K
): Effect.Effect<void>
}
Removes a fiber from the FiberMap, interrupting it if it exists.
Example (Removing a fiber)
import { Effect, FiberMap } from "effect"
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)
console.log(yield* FiberMap.size(map)) // 2
// Remove a specific fiber (this will interrupt it)
yield* FiberMap.remove(map, "task1")
console.log(yield* FiberMap.size(map)) // 1
})
remove: {
<function (type parameter) K in <K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<void>K>(key: Kkey: function (type parameter) K in <K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<void>K): <function (type parameter) A in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<void>A, function (type parameter) E in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<void>E>(self: FiberMap<K, A, E>(parameter) self: {
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;
}
self: 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>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<void>K, function (type parameter) A in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<void>A, function (type parameter) E in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<void>E>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>
<function (type parameter) K in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>E>(self: FiberMap<K, A, E>(parameter) self: {
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;
}
self: 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, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>E>, key: Kkey: function (type parameter) K in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>K): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>
} = dual<<K>(key: K) => <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<void>, <K, A, E>(self: FiberMap<K, A, E>, key: K) => Effect.Effect<void>>(arity: 2, body: <K, A, E>(self: FiberMap<K, A, E>, key: K) => Effect.Effect<void>): (<K>(key: K) => <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<void>) & (<K, A, E>(self: FiberMap<K, A, E>, key: K) => Effect.Effect<void>) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual<
<function (type parameter) K in <K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<void>K>(
key: Kkey: function (type parameter) K in <K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<void>K
) => <function (type parameter) A in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<void>A, function (type parameter) E in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<void>E>(self: FiberMap<K, A, E>(parameter) self: {
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;
}
self: 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>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<void>K, function (type parameter) A in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<void>A, function (type parameter) E in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<void>E>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>,
<function (type parameter) K in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>E>(
self: FiberMap<K, A, E>(parameter) self: {
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;
}
self: 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, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>E>,
key: Kkey: function (type parameter) K in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<void>K
) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>
>(2, (self: FiberMap<K, A, E>(parameter) self: {
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;
}
self, key: Kkey) =>
import EffectEffect.suspend(() => {
if (self: FiberMap<K, A, E>(parameter) self: {
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;
}
self.FiberMap<K, A, E>.state: { readonly _tag: "Open"; readonly backing: MutableHashMap.MutableHashMap<K, Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" }state._tag: "Open" | "Closed"_tag === "Closed") {
return import EffectEffect.void
}
const const fiber: Option.Option<
Fiber.Fiber<A, E>
>
fiber = import MutableHashMapMutableHashMap.const get: {
<K>(key: K): <V>(
self: MutableHashMap<K, V>
) => Option.Option<V>
<K, V>(
self: MutableHashMap<K, V>,
key: K
): Option.Option<V>
}
get(self: FiberMap<K, A, E>(parameter) self: {
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;
}
self.FiberMap<K, A, E>.state: { readonly _tag: "Open"; readonly backing: MutableHashMap.MutableHashMap<K, Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" }state.backing: MutableHashMap.MutableHashMap<
K,
Fiber.Fiber<A, E>
>
(property) backing: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
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;
}
backing, key: Kkey)
if (const fiber: Option.Option<
Fiber.Fiber<A, E>
>
fiber._tag: "None" | "Some"_tag === "None") {
return import EffectEffect.void
}
return import FiberFiber.interruptAs(const fiber: Option.Some<
Fiber.Fiber<A, E>
>
const fiber: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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;
}
fiber.Some<Fiber.Fiber<A, E>>.value: Fiber.Fiber<A, E>(property) Some<Fiber.Fiber<A, E>>.value: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | undefined;
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; <…;
}
value, const internalFiberId: -1internalFiberId)
}))