Hyperlinkv0.8.0-beta.28

FiberMap

FiberMap.hasconsteffect/FiberMap.ts:602
<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
})
combinators
export 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>
} = dual(
  2,
  <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<boolean> => Effect.sync(() => hasUnsafe(self, key))
)