Hyperlinkv0.8.0-beta.28

SchemaParser

SchemaParser.makeOptionfunctioneffect/SchemaParser.ts:101
<S extends Schema.Constraint>(schema: S): (
  input: S["~type.make.in"],
  options?: Schema.MakeOptions
) => Option.Option<S["Type"]>

Creates a synchronous maker that returns Option.some with the constructed value on success, or Option.none when construction fails with schema issues.

When to use

Use when you need to validate schema constructor input and only care whether construction succeeds, without exposing SchemaIssue.Issue details.

Gotchas

Only causes made entirely of schema issues are converted to Option.none. Causes that contain defects, interruptions, or asynchronous work at this synchronous boundary throw an Error whose cause is the underlying Cause.

constructors
export function makeOption<S extends Schema.Constraint>(schema: S) {
  const parser = makeEffect(schema)
  return (input: S["~type.make.in"], options?: Schema.MakeOptions): Option.Option<S["Type"]> => {
    const exit = Effect.runSyncExit(parser(input, options))
    if (Exit.isSuccess(exit)) {
      return Option.some(exit.value)
    }
    InternalSchemaCause.getSchemaIssueOrThrow(exit.cause, "Option adapter can only return none for schema issues")
    return Option.none()
  }
}
Referenced by 1 symbols