def digits
import bend-kit-llm@0.13.0.1/sse.bend as Sseimport Base
74# Base-ten digits, at most 9 of them; None for any other text.
75def digits(s: String, +acc: U32, +n: U32, bad: Bool) -> Maybe<&2, U32>:
76 match s:
77 case SNil{}:
78 Bool.pick(Maybe<&2, U32>, Bool.or(bad, Bool.or(U32.is_zero(n), U32.is_lt(9, n))), None{}, Some{acc})
79 case SCon{Chr{+c}, t}:
80 digits(t, (acc * 10 + (c - 48 : U32) : U32), (n + 1 : U32), Bool.or(bad, Bool.or(U32.is_lt(c, 48), U32.is_lt(57, c))))