<K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<boolean>
<K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean>Checks whether a key exists in the FiberMap.
This is the Effect-wrapped version of hasUnsafe.
Example (Checking if a key exists)
import { Effect, FiberMap } from "effect"
const program = Effect.gen(function*() {
const map = yield* FiberMap.make<string>()
// Add a fiber to the map
yield* FiberMap.run(map, "task1", Effect.never)
// Check if keys exist using Effect
const exists1 = yield* FiberMap.has(map, "task1")
const exists2 = yield* FiberMap.has(map, "task2")
console.log(exists1) // true
console.log(exists2) // false
})export const const has: {
<K>(key: K): <A, E>(
self: FiberMap<K, A, E>
) => Effect.Effect<boolean>
<K, A, E>(
self: FiberMap<K, A, E>,
key: K
): Effect.Effect<boolean>
}
Checks whether a key exists in the FiberMap.
This is the Effect-wrapped version of hasUnsafe.
Example (Checking if a key exists)
import { Effect, FiberMap } from "effect"
const program = Effect.gen(function*() {
const map = yield* FiberMap.make<string>()
// Add a fiber to the map
yield* FiberMap.run(map, "task1", Effect.never)
// Check if keys exist using Effect
const exists1 = yield* FiberMap.has(map, "task1")
const exists2 = yield* FiberMap.has(map, "task2")
console.log(exists1) // true
console.log(exists2) // false
})
has: {
<function (type parameter) K in <K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<boolean>K>(key: Kkey: function (type parameter) K in <K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<boolean>K): <function (type parameter) A in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<boolean>A, function (type parameter) E in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<boolean>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<boolean>K, function (type parameter) A in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<boolean>A, function (type parameter) E in <A, E>(self: FiberMap<K, A, E>): Effect.Effect<boolean>E>) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<boolean>
<function (type parameter) K in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean>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<boolean>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean>E>, key: Kkey: function (type parameter) K in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean>K): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<boolean>
} = dual<(...args: Array<any>) => any, <K, A, E>(self: FiberMap<K, A, E>, key: K) => Effect.Effect<boolean>>(arity: 2, body: <K, A, E>(self: FiberMap<K, A, E>, key: K) => Effect.Effect<boolean>): ((...args: Array<any>) => any) & (<K, A, E>(self: FiberMap<K, A, E>, key: K) => Effect.Effect<boolean>) (+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<boolean>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean>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<boolean>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean>E>, key: Kkey: function (type parameter) K in <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean>K): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<boolean> => import EffectEffect.const sync: <A>(
thunk: LazyArg<A>
) => Effect<A>
Creates an Effect that represents a synchronous side-effectful computation.
When to use
Use when you need to wrap a synchronous side-effectful operation that is not
expected to throw.
Details
The provided function is evaluated lazily when the effect runs.
Gotchas
The function must not throw. If it throws, the thrown value is treated as a
defect, not as a typed failure. Use try when throwing is expected.
Example (Capturing synchronous logging in an Effect)
import { Effect } from "effect"
const log = (message: string) =>
Effect.sync(() => {
console.log(message) // side effect
})
// ┌─── Effect<void, never, never>
// ▼
const program = log("Hello, World!")
sync(() => const hasUnsafe: {
<K>(key: K): <A, E>(
self: FiberMap<K, A, E>
) => boolean
<K, A, E>(
self: FiberMap<K, A, E>,
key: K
): boolean
}
hasUnsafe(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))
)