lazy/lazy.bend source
lazy/lazy.bend on the hub · documented module
# lazy: branches that do not run both ways. Bool.pick, Bool.and and Bool.or# are ordinary defs, so every argument is evaluated before the call: a# search written as `Bool.pick(T, hit, here, go(rest))` walks the whole list# whatever `hit` says (measured native, 100 iterations over 100k cells: the# hit at the head costs 0.10 s, the same as the hit at the end, while the# forms here cost 0.00 s). A thunk `Unit -> T` is a value, so the branch# that is not taken is never applied.import Base# `a` when c, else what rest gives: the early exit of a searchdef stop(-A: Type, c: Bool, a: A, rest: Unit -> A) -> A: match c: case True{}: a case False{}: rest(Unit{})# True when a, else what rest gives: `or` that stops at the first Truedef or_else(a: Bool, rest: Unit -> Bool) -> Bool: match a: case True{}: True{} case False{}: rest(Unit{})# what rest gives when a, else False: `and` that stops at the first Falsedef and_then(a: Bool, rest: Unit -> Bool) -> Bool: match a: case True{}: rest(Unit{}) case False{}: False{}