Hyperlinkv0.8.0-beta.28

SchemaGetter

SchemaGetter.transformOrFailfunctioneffect/SchemaGetter.ts:539
<T, E, R = never>(
  f: (
    e: E,
    options: SchemaAST.ParseOptions
  ) => Effect.Effect<T, SchemaIssue.Issue, R>
): Getter<T, E, R>

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

  • Skips None inputs — only called when a value is present.
  • On success, wraps the result in Some.
  • On failure, propagates the Issue.

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)
  }
)
constructorstransformonSome
export function transformOrFail<T, E, R = never>(
  f: (e: E, options: SchemaAST.ParseOptions) => Effect.Effect<T, SchemaIssue.Issue, R>
): Getter<T, E, R> {
  return onSome((e, options) => f(e, options).pipe(Effect.mapEager(Option.some)))
}
Referenced by 10 symbols