def opt_at

bend-schema-lib@0.4.1.0 · core.bend:1692

import bend-schema-lib@0.4.1.0/core.bend as Core
import Base

1692# An absent value reaches the top of what enc writes for s: s is an SOptional,
1693# or it hands the value it was given straight to a schema that is (a rule, a
1694# strict object, a bound, or the tail of a variant or tagged chain -- and an
1695# SOpt, whose Some case passes the value through). Everything else wraps what
1696# it writes in a constructor of its own, so an absent value cannot surface.
1697def opt_at(s: Schema) -> Bool:
1698  match s:
1699    case SOptional{i}:
1700      True{}
1701    case SOpt{i}:
1702      opt_at(i)
1703    case SRule{s2, tag}:
1704      opt_at(s2)
1705    case SStrict{s2}:
1706      opt_at(s2)
1707    case SStrLen{lo, hi, s2}:
1708      opt_at(s2)
1709    case SListLen{lo, hi, s2}:
1710      opt_at(s2)
1711    case STagged{k, n, cs, rest}:
1712      opt_at(rest)
1713    case SVariant{n, vs, rest}:
1714      opt_at(rest)
1715    case _:
1716      False{}

Uses (2)

Used by (1)