Hyperlinkv0.8.0-beta.28

SchemaGetter

SchemaGetter.transformOptionalfunctioneffect/SchemaGetter.ts:574
<T, E>(f: (oe: Option.Option<E>) => Option.Option<T>): Getter<T, E>

Creates a getter that transforms the full Option — both present and absent values.

When to use

Use when you need a schema getter to handle both Some and None cases.

Details

The getter is pure and never fails. It receives the full Option<E> and must return Option<T>, so it can turn a present value into absent or an absent value into present.

Example (Filtering out empty strings)

import { Option, SchemaGetter } from "effect"

const skipEmpty = SchemaGetter.transformOptional<string, string>((o) =>
  Option.filter(o, (s) => s.length > 0)
)
constructorstransformomit
export function transformOptional<T, E>(f: (oe: Option.Option<E>) => Option.Option<T>): Getter<T, E> {
  return new Getter((oe) => Effect.succeed(f(oe)))
}
Referenced by 3 symbols