Hyperlinkv0.8.0-beta.28

Predicate

Predicate.isPromisefunctioneffect/Predicate.ts:1317
(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 isPromise(input: unknown): input is Promise<unknown> {
  return hasProperty(input, "then") && "catch" in input && isFunction(input.then) && isFunction(input.catch)
}