(u: unknown): u is TxSemaphoreDetermines if the provided value is a TxSemaphore.
When to use
Use to narrow an unknown value before treating it as a TxSemaphore.
Example (Checking semaphore values)
import { Effect, TxSemaphore } from "effect"
const program = Effect.gen(function*() {
const semaphore = yield* TxSemaphore.make(5)
const notSemaphore = { some: "object" }
console.log(TxSemaphore.isTxSemaphore(semaphore)) // true
console.log(TxSemaphore.isTxSemaphore(notSemaphore)) // false
// Useful for runtime type checking in generic functions
if (TxSemaphore.isTxSemaphore(semaphore)) {
const available = yield* TxSemaphore.available(semaphore)
console.log(`Available permits: ${available}`)
}
})guardsmake
Source effect/TxSemaphore.ts:7071 lines
export const const isTxSemaphore: (
u: unknown
) => u is TxSemaphore
Determines if the provided value is a TxSemaphore.
When to use
Use to narrow an unknown value before treating it as a TxSemaphore.
Example (Checking semaphore values)
import { Effect, TxSemaphore } from "effect"
const program = Effect.gen(function*() {
const semaphore = yield* TxSemaphore.make(5)
const notSemaphore = { some: "object" }
console.log(TxSemaphore.isTxSemaphore(semaphore)) // true
console.log(TxSemaphore.isTxSemaphore(notSemaphore)) // false
// Useful for runtime type checking in generic functions
if (TxSemaphore.isTxSemaphore(semaphore)) {
const available = yield* TxSemaphore.available(semaphore)
console.log(`Available permits: ${available}`)
}
})
isTxSemaphore = (u: unknownu: unknown): u: unknownu is TxSemaphore => hasProperty<"~effect/transactions/TxSemaphore">(self: unknown, property: "~effect/transactions/TxSemaphore"): self is { [K in "~effect/transactions/TxSemaphore"]: unknown; } (+1 overload)Checks whether a value has a given property key.
When to use
Use when you need a Predicate guard for property access on unknown
values with a simple structural object check.
Details
Uses the in operator and isObjectKeyword. This does not check property
value types.
Example (Guarding object properties)
import { Predicate } from "effect"
const hasName = Predicate.hasProperty("name")
const data: unknown = { name: "Ada" }
if (hasName(data)) {
console.log(data.name)
}
hasProperty(u: unknownu, const TypeId: "~effect/transactions/TxSemaphore"TypeId)