lazy/lazy.bend checks
raw source on the hub · import 0x729eecea86ea5a2cdba3a2856a313bca/lazy/lazy.bend as Lazy
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.
1 import
import Base
Definitions
def stop source · line 11 · raw
@-A:Type -> @c:Bool -> @a:A -> @rest:(@_:Unit -> A) -> A
a when c, else what rest gives: the early exit of a search
def or_else source · line 19 · raw
@a:Bool -> @rest:(@_:Unit -> Bool) -> Bool
True when a, else what rest gives: or that stops at the first True
def and_then source · line 27 · raw
@a:Bool -> @rest:(@_:Unit -> Bool) -> Bool
what rest gives when a, else False: and that stops at the first False