Core.check: def of bend-schema-lib@0.4.1.0 Import: import bend-schema-lib@0.4.1.0/core.bend as Core Lines 850-955 of bend-schema-lib@0.4.1.0/core.bend: https://jend.leeeet.dev/read.txt?path=bend-schema-lib@0.4.1.0/core.bend&start_line=850&end_line=955 import Base def check(~rule: Nat -> Raw -> Maybe<&2, Err>, s: Schema, r: Raw, +prev: Maybe<&2, Nat>) -> Maybe<&2, Err>: match s r: case SNat{} RNum{n}: None{} case SNat{} x: here(missing_or(x, NotNat{})) case SStr{} RStr{x}: None{} case SStr{} x: here(missing_or(x, NotString{})) case SNatIn{+lo, +hi} RNum{+n}: nat_in(lo, hi, RNum{n}) case SNatIn{lo_, hi_} +x: here(missing_or(x, NotNat{})) case SStrLen{+lo, +hi, +s2} +x: first(check(~rule, s2, x, prev), len_err(lo, hi, x)) case SListLen{+lo, +hi, +s2} +r: first(count_err(lo, hi, r), check(~rule, s2, r, None{})) case SOpt{inner} RNull{}: None{} case SOpt{inner} x: check(~rule, inner, x, None{}) case SOptional{inner} RMissing{}: None{} case SOptional{inner} x: check(~rule, inner, x, None{}) case SList{e} RNil{}: None{} case SList{+e} RCons{h, t}: first(under(AtIndex{0n}, check(~rule, e, h, None{})), later_l(check(~rule, SList{e}, t, None{}))) case SJson{} RJson{value}: in_err(valid_json(value), NotJson{}) case SJson{} x: here(missing_or(x, NotJson{})) case SInt{} RNum{n}: None{} case SInt{} RNeg{n}: None{} case SInt{} x: here(missing_or(x, NotInt{})) case SIntIn{+lo, +hi} RNum{+n}: in_err(int_ok(lo, hi, IPos{n}), IntNotIn{lo, hi}) case SIntIn{+lo, +hi} RNeg{+n}: in_err(int_ok(lo, hi, INeg{n}), IntNotIn{lo, hi}) case SIntIn{lo_, hi_} x: here(missing_or(x, NotInt{})) case SList{e} x: here(missing_or(x, NotList{})) case SField{+name, fs, rest} REnd{}: first(under(AtField{0n, name}, check(~rule, fs, RMissing{}, None{})), later_f(check(~rule, rest, REnd{}, None{}))) case SField{+name, fs, rest} RKey{+k, +v, +o}: first(key_err(key_once(name, RKey{k, v, o}), name), first(under(AtField{0n, name}, check(~rule, fs, lookup(name, RKey{k, v, o}), None{})), later_f(check(~rule, rest, RKey{k, v, o}, None{})))) case SField{name, fs, rest} x: here(missing_or(x, NotObject{})) case SEnd{} REnd{}: None{} case SEnd{} RKey{k, v, o}: None{} case SEnd{} x: here(missing_or(x, NotObject{})) case SRule{+s2, +tag} +x: first(check(~rule, s2, x, prev), rule(tag, x)) case SStrict{+s2} +x: first(check(~rule, s2, x, prev), extra_err(key_names(s2), x)) case STagged{+k, +n, cs, rest} +x: pick_err(is_tag(k, n, x), first(key_err(key_once(k, x), k), check(~rule, cs, drop_key(k, x), None{})), check(~rule, rest, x, None{})) case STagEnd{k} x: tag_err(k, x) case SBool{} RBool{b}: None{} case SBool{} +x: here(missing_or(x, NotBool{})) case STrue{} RBool{b}: true_err(b) case STrue{} x: here(missing_or(x, NotTrue{})) case SEnum{names} RStr{+x}: enum_err(in_names(x, names)) case SEnum{names} x: here(missing_or(x, NotOneOf{})) case SVariant{+name, +vs, +rest} REnd{}: later_f(check(~rule, rest, REnd{}, None{})) case SVariant{+name, +vs, +rest} RKey{+k, +v, +o}: pick_err(is_missing(lookup(name, RKey{k, v, o})), later_f(check(~rule, rest, RKey{k, v, o}, None{})), first(key_err(key_once(name, RKey{k, v, o}), name), first(under(AtField{0n, name}, check(~rule, vs, lookup(name, RKey{k, v, o}), None{})), later_f(dup_err(rest, RKey{k, v, o}))))) case SVariant{+name, +vs, +rest} x: here(missing_or(x, NotObject{})) case SVEnd{} REnd{}: here(NoVariant{}) case SVEnd{} RKey{k, v, o}: here(NoVariant{}) case SVEnd{} x: here(missing_or(x, NotObject{})) case STuple{ts, rest} RCons{h, t}: first(under(AtIndex{0n}, check(~rule, ts, h, None{})), later_l(check(~rule, rest, t, None{}))) case STuple{ts, rest} RNil{}: here(TooShort{}) case STuple{ts, rest} x: here(missing_or(x, NotList{})) case STEnd{} RNil{}: None{} case STEnd{} RCons{h, t}: here(TooLong{}) case STEnd{} x: here(missing_or(x, NotList{})) case SEither{+l, +r} +x: pick_err(has_kind(l, kind_of(x)), check(~rule, l, x, prev), pick_err(has_kind(r, kind_of(x)), check(~rule, r, x, prev), here(missing_or(x, no_alt(SEither{l, r}))))) Uses (37): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Maybe https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=Err https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=Int https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=Raw https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=Schema https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=Step https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=Why https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=count_err https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=drop_key https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=dup_err https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=enum_err https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=extra_err https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=first https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=has_kind https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=here https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=in_err https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=in_names https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=int_ok https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=is_missing https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=is_tag https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=key_err https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=key_names https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=key_once https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=kind_of https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=later_f https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=later_l https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=len_err https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=lookup https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=missing_or https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=nat_in https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=no_alt https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=pick_err https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=tag_err https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=true_err https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=under https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=valid_json