effect-io-ai

Package: effect
Module: SchemaGetter

SchemaGetter.transformOrFail

Creates a getter that applies a fallible, effectful transformation to present values.

When to use

Use when you need a schema getter for a transformation that may fail, require Effect services, or run asynchronously.

Details

Example (Parsing with failure)

import { Effect, Option, SchemaGetter, SchemaIssue } from "effect"

const safeParseInt = SchemaGetter.transformOrFail<number, string>(
  (s) => {
    const n = parseInt(s, 10)
    return isNaN(n)
      ? Effect.fail(new SchemaIssue.InvalidValue(Option.some(s), { message: "not an integer" }))
      : Effect.succeed(n)
  }
)

See

Signature

declare const transformOrFail: <T, E, R = never>(f: (e: E, options: SchemaAST.ParseOptions) => Effect.Effect<T, SchemaIssue.Issue, R>) => Getter<T, E, R>

Source

Since v4.0.0