Hyperlinkv0.8.0-beta.28

Optic

Optic.fromChecksfunctioneffect/Optic.ts:316
<T>(
  checks_0: SchemaAST.Check<T>,
  ...checks: Array<SchemaAST.Check<T>>
): Prism<T, T>

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).

  • You already have Schema.isGreaterThan, Schema.isInt, etc.

Details

  • getResult runs all checks; fails with a combined error message when any check fails.
  • set is identity — the value passes through unchanged.

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
constructorsPrismmakePrism
Source effect/Optic.ts:3163 lines
export function fromChecks<T>(...checks: readonly [SchemaAST.Check<T>, ...Array<SchemaAST.Check<T>>]): Prism<T, T> {
  return make(new CheckNode(checks))
}