Hyperlinkv0.8.0-beta.28

SchemaGetter

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

Creates a getter that handles present values (Option.Some), passing None through.

When to use

Use when you need a schema getter to transform or validate only when a field value is present.

  • Missing keys should remain absent in the output.

Details

  • When input is None, returns None (no-op).
  • When input is Some(e), calls f(e, options) to produce the result.
  • f may return None to omit the value, or fail with an Issue.

Example (Transforming only present values)

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

const parseIfPresent = SchemaGetter.onSome<number, string>(
  (s) => Effect.succeed(Option.some(Number(s)))
)
export function onSome<T, E, R = never>(
  f: (e: E, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>
): Getter<T, E, R> {
  return new Getter((oe, options) => Option.isNone(oe) ? Effect.succeedNone : f(oe.value, options))
}
Referenced by 4 symbols