~/bend-docscommunity

src/lazy/lazy.bend checks

raw source on the hub · import 0xd96f2ab40f5df4925c42e96d0ba857ff/src/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 -> @cc:Bool -> @aa: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

@aa: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

@aa:Bool -> @rest:(@_:Unit -> Bool) -> Bool

what rest gives when a, else False: and that stops at the first False

def either source · line 36 · raw

@-A:Type -> @cc:Bool -> @yes:(@_:Unit -> A) -> @no:(@_:Unit -> A) -> A

what yes gives when c, else what no gives: a pick whose two branches each recurse, only the one taken run