<K>(key: K): <A, E>(
self: FiberMap<K, A, E>
) => Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>
<K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<
Option.Option<Fiber.Fiber<A, E>>
>Retrieves a fiber from the FiberMap effectfully.
Details
Returns an Option wrapped in Effect.
Example (Retrieving a fiber)
import { Deferred, Effect, Fiber, FiberMap } from "effect"
const program = Effect.gen(function*() {
const map = yield* FiberMap.make<string>()
const deferred = yield* Deferred.make<string>()
// Add a fiber to the map
const fiber = yield* Effect.forkChild(Deferred.await(deferred))
yield* FiberMap.set(map, "greeting", fiber)
// Retrieve the fiber with error handling
const retrieved = yield* FiberMap.get(map, "greeting")
if (retrieved._tag === "Some") {
yield* Deferred.succeed(deferred, "Hello")
const result = yield* Fiber.join(retrieved.value)
console.log(result) // "Hello"
}
})export const const get: {
<K>(key: K): <A, E>(
self: FiberMap<K, A, E>
) => Effect.Effect<
Option.Option<Fiber.Fiber<A, E>>
>
<K, A, E>(
self: FiberMap<K, A, E>,
key: K
): Effect.Effect<
Option.Option<Fiber.Fiber<A, E>>
>
}
Retrieves a fiber from the FiberMap effectfully.
Details
Returns an Option wrapped in Effect.
Example (Retrieving a fiber)
import { Deferred, Effect, Fiber, FiberMap } from "effect"
const program = Effect.gen(function*() {
const map = yield* FiberMap.make<string>()
const deferred = yield* Deferred.make<string>()
// Add a fiber to the map
const fiber = yield* Effect.forkChild(Deferred.await(deferred))
yield* FiberMap.set(map, "greeting", fiber)
// Retrieve the fiber with error handling
const retrieved = yield* FiberMap.get(map, "greeting")
if (retrieved._tag === "Some") {
yield* Deferred.succeed(deferred, "Hello")
const result = yield* Fiber.join(retrieved.value)
console.log(result) // "Hello"
}
})
get: {
<function (type parameter) K in <K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>K>(key: Kkey: function (type parameter) K in <K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>K): <function (type parameter) A in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>A, function (type parameter) E in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>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<Option.Option<Fiber.Fiber<A, E>>>K, function (type parameter) A in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>A, function (type parameter) E in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>E>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<import FiberFiber.type Fiber.Fiber = /*unresolved*/ anyFiber<function (type parameter) A in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>A, function (type parameter) E in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>E>>>
<function (type parameter) K in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>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<Option.Option<Fiber.Fiber<A, E>>>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>E>, key: Kkey: function (type parameter) K in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>K): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<import FiberFiber.type Fiber.Fiber = /*unresolved*/ anyFiber<function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>E>>>
} = dual<(...args: Array<any>) => any, <K, A, E>(self: FiberMap<K, A, E>, key: K) => Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>>(arity: 2, body: <K, A, E>(self: FiberMap<K, A, E>, key: K) => Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>): ((...args: Array<any>) => any) & (<K, A, E>(self: FiberMap<K, A, E>, key: K) => Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>) (+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(
2,
<function (type parameter) K in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>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<Option.Option<Fiber.Fiber<A, E>>>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>E>, key: Kkey: function (type parameter) K in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>K): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<import FiberFiber.type Fiber.Fiber = /*unresolved*/ anyFiber<function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>E>>> =>
import EffectEffect.suspend(() => import EffectEffect.succeed(const getUnsafe: {
<K>(key: K): <A, E>(
self: FiberMap<K, A, E>
) => Option.Option<Fiber.Fiber<A, E>>
<K, A, E>(
self: FiberMap<K, A, E>,
key: K
): Option.Option<Fiber.Fiber<A, E>>
}
getUnsafe(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)))
)