MCPcopy Create free account
hub / github.com/Effect-TS/effect / parseUnionCandidates

Function parseUnionCandidates

packages/effect/src/SchemaAST.ts:3886–3915  ·  view source on GitHub ↗
(
  ast: Union,
  parser: (i: number) => SchemaParser.Parser,
  candidates: ReadonlyArray<number>,
  input: unknown,
  options: ParseOptions
)

Source from the content-addressed store, hash-verified

3884}
3885
3886function parseUnionCandidates(
3887 ast: Union,
3888 parser: (i: number) => SchemaParser.Parser,
3889 candidates: ReadonlyArray<number>,
3890 input: unknown,
3891 options: ParseOptions
3892): Effect.Effect<unknown, SchemaIssue.Issue, any> {
3893 const state: UnionParserState = {
3894 ast,
3895 parser,
3896 input,
3897 out: undefined,
3898 successes: ast.options?.mode === "oneOf" ? [] : undefined,
3899 issues: undefined,
3900 options
3901 }
3902 const eff = parseUnion(state, candidates)
3903 if (!eff) {
3904 if (state.out) return state.out
3905 return Effect.fail(new SchemaIssue.AnyOf(ast, state.issues ?? [], input, options))
3906 }
3907 if (effectIsExit(eff)) return resumeUnion(eff, state)
3908 // Reparse on later runs to avoid reusing mutable traversal state.
3909 let first = true
3910 return Effect.suspend(() => {
3911 if (!first) return parseUnionCandidates(ast, parser, candidates, input, options)
3912 first = false
3913 return resumeUnion(eff, state)
3914 })
3915}
3916
3917function resumeUnion(
3918 eff: Effect.Effect<void, SchemaIssue.Issue, any>,

Callers 1

getParserMethod · 0.85

Calls 3

effectIsExitFunction · 0.90
resumeUnionFunction · 0.85
failMethod · 0.65

Tested by

no test coverage detected