Core.conforms: def of bend-schema-lib@0.4.1.0 Import: import bend-schema-lib@0.4.1.0/core.bend as Core Lines 624-689 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=624&end_line=689 import Base def conforms(~rule: Nat -> Raw -> Maybe<&2, Err>, s: Schema, r: Raw, +prev: Maybe<&2, Nat>) -> Bool: match s r: case SNat{} RNum{n}: True{} case SNatIn{+lo, +hi} RNum{+n}: num_ok(lo, hi, n) case SStr{} RStr{x}: True{} case SStrLen{+lo, +hi, +s2} +x: Bool.and(conforms(~rule, s2, x, prev), len_ok(lo, hi, x)) case SListLen{+lo, +hi, +s2} +r: Bool.and(list_len_ok(lo, hi, r), conforms(~rule, s2, r, None{})) case SOpt{inner} RNull{}: True{} case SOpt{inner} x: conforms(~rule, inner, x, None{}) case SOptional{+inner} +x: Bool.or(is_missing(x), conforms(~rule, inner, x, None{})) case SList{e} RNil{}: True{} case SList{+e} RCons{h, t}: Bool.and(conforms(~rule, e, h, None{}), conforms(~rule, SList{e}, t, None{})) case SJson{} RJson{value}: valid_json(value) case SInt{} RNum{n}: True{} case SInt{} RNeg{n}: True{} case SIntIn{+lo, +hi} RNum{+n}: int_ok(lo, hi, IPos{n}) case SIntIn{+lo, +hi} RNeg{+n}: int_ok(lo, hi, INeg{n}) case SField{+name, fs, rest} REnd{}: Bool.and(conforms(~rule, fs, RMissing{}, None{}), conforms(~rule, rest, REnd{}, None{})) case SField{+name, fs, rest} RKey{+k, +v, +o}: Bool.and(key_once(name, RKey{k, v, o}), Bool.and(conforms(~rule, fs, lookup(name, RKey{k, v, o}), None{}), conforms(~rule, rest, RKey{k, v, o}, None{}))) case SEnd{} REnd{}: True{} case SEnd{} RKey{k, v, o}: True{} case SRule{+s2, +tag} +x: Bool.and(conforms(~rule, s2, x, prev), Maybe.is_none(&2, Err, rule(tag, x))) case SStrict{+s2} +x: Bool.and(conforms(~rule, s2, x, prev), no_extra(key_names(s2), x)) case STagged{+k, +n, cs, rest} +x: pick_bool(is_tag(k, n, x), Bool.and(key_once(k, x), conforms(~rule, cs, drop_key(k, x), None{})), conforms(~rule, rest, x, None{})) case STagEnd{k} x: False{} # the end of a tagged chain: no case matched case SBool{} RBool{b}: True{} # any boolean is a boolean, and nothing else is case STrue{} RBool{b}: b case SEnum{names} RStr{+x}: in_names(x, names) case SVariant{+name, +vs, +rest} REnd{}: conforms(~rule, rest, REnd{}, None{}) case SVariant{+name, +vs, +rest} RKey{+k, +v, +o}: pick_bool(is_missing(lookup(name, RKey{k, v, o})), conforms(~rule, rest, RKey{k, v, o}, None{}), Bool.and(key_once(name, RKey{k, v, o}), Bool.and(conforms(~rule, vs, lookup(name, RKey{k, v, o}), None{}), none_present(rest, RKey{k, v, o})))) case STuple{ts, rest} RCons{h, t}: Bool.and(conforms(~rule, ts, h, None{}), conforms(~rule, rest, t, None{})) case STEnd{} RNil{}: True{} case SEither{+l, +r} +x: pick_bool(has_kind(l, kind_of(x)), conforms(~rule, l, x, prev), Bool.and(has_kind(r, kind_of(x)), conforms(~rule, r, x, prev))) case _ _: False{} Uses (27): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.and https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.or https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Maybe https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Maybe.is_none 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=drop_key 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=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_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=len_ok https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=list_len_ok 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=no_extra https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=none_present https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=num_ok https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=pick_bool https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=valid_json