(input: unknown): input is Promise<unknown>Checks whether a value is a Promise-like object with then and catch.
When to use
Use when you need a Predicate guard for promise instances across realms.
Details
Performs a structural check for then and catch functions.
Example (Guarding promises)
import { Predicate } from "effect"
const data: unknown = Promise.resolve(1)
console.log(Predicate.isPromise(data))export function function isPromise(
input: unknown
): input is Promise<unknown>
Checks whether a value is a Promise-like object with then and catch.
When to use
Use when you need a Predicate guard for promise instances across realms.
Details
Performs a structural check for then and catch functions.
Example (Guarding promises)
import { Predicate } from "effect"
const data: unknown = Promise.resolve(1)
console.log(Predicate.isPromise(data))
isPromise(input: unknowninput: unknown): input: unknowninput is interface Promise<T>Represents the completion of an asynchronous operation
Promise<unknown> {
return const hasProperty: <"then">(self: unknown, property: "then") => self is { [K in "then"]: unknown; } (+1 overload)hasProperty(input: unknowninput, "then") && "catch" in input: {
then: unknown
}
input && function isFunction(
input: unknown
): input is Function
Checks whether a value is a function.
When to use
Use when you need a Predicate guard to narrow an unknown value to a
callable function.
Details
Uses typeof input === "function".
Example (Guarding functions)
import { Predicate } from "effect"
const data: unknown = () => 1
if (Predicate.isFunction(data)) {
console.log(data())
}
isFunction(input: {
then: unknown
} & Record<"catch", unknown>
input.then: unknownthen) && function isFunction(
input: unknown
): input is Function
Checks whether a value is a function.
When to use
Use when you need a Predicate guard to narrow an unknown value to a
callable function.
Details
Uses typeof input === "function".
Example (Guarding functions)
import { Predicate } from "effect"
const data: unknown = () => 1
if (Predicate.isFunction(data)) {
console.log(data())
}
isFunction(input: {
then: unknown
} & Record<"catch", unknown>
input.catch: unknowncatch)
}