effect-io-ai

Package: effect
Module: Filter

Filter.instanceOf

Creates a filter that only passes instances of the given constructor.

When to use

Use to narrow unknown input to values created by a specific JavaScript constructor while keeping the result in the Filter / Result pipeline.

Details

The filter succeeds when the input satisfies instanceof constructor. Otherwise it fails with the original input.

Gotchas

This uses JavaScript instanceof semantics, including prototype-chain and realm behavior.

See

Signature

declare const instanceOf: <K extends new (...args: any) => any>(constructor: K) => <Input>(u: Input) => Result.Result<InstanceType<K>, Exclude<Input, InstanceType<K>>>

Source

Since v4.0.0