opel
opel copied to clipboard
Introduce `lazyval`
WHY:
currently long boolean expressions cannot be organized and still benefit from lazy evaluation of boolean expressions
ex:
(heavyComputationFromASource1() && heavyComputationFromASource2()) || (heavyComputationFromBSource1() && heavyComputationFromBSource2()) || (heavyComputationFromCSource1() && heavyComputationFromCSource2())
is not equivalent to
val a = heavyComputationFromASource1() && heavyComputationFromASource2()
val b = heavyComputationFromBSource1() && heavyComputationFromBSource2()
val c = heavyComputationFromCSource1() && heavyComputationFromCSource2()
a || b || c
as at least *Source1() will be evaluated
PROPOSAL:
With lazyval working under the hood as some kind of supplier code below would work and still benefit from lazy evaluation
lazyval a = heavyComputationFromASource1() && heavyComputationFromASource2()
lazyval b = heavyComputationFromBSource1() && heavyComputationFromBSource2()
lazyval c = heavyComputationFromCSource1() && heavyComputationFromCSource2()
a || b || c