effect-io-ai

Package: effect
Module: Optic

Optic.fromChecks

Creates a Prism from one or more Schema validation checks.

When to use

Use when you want to narrow T to the subset that passes certain validation rules (e.g. positive integer).

Details

Example (Creating a positive integer prism)

import { Optic, Result, Schema } from "effect"

const posInt = Optic.fromChecks<number>(
  Schema.isGreaterThan(0),
  Schema.isInt()
)

console.log(Result.isSuccess(posInt.getResult(3)))
// Output: true

console.log(Result.isFailure(posInt.getResult(-1)))
// Output: true

See

Signature

declare const fromChecks: <T>(checks_0: SchemaAST.Check<T>, ...checks: Array<SchemaAST.Check<T>>) => Prism<T, T>

Source

Since v4.0.0