September 2015
Intermediate to advanced
250 pages
6h 40m
English
If you’re new to lazy evaluation, you probably have used it without really calling it that. Many languages support short-circuit evaluation for conditions. If the evaluation of an argument in a condition with multiple && or || is enough to determine the truth, then the remaining arguments in that expression are not evaluated. Here’s an example of a simple short-circuit evaluation.
| Parallel/shortCircuit.scala | |
| | def expensiveComputation() = { |
| | println("...assume slow operation...") |
| | false |
| | } |
| | |
| | def evaluate(input: Int) = { |
| | println(s"evaluate called with $input") |
| | if(input >= 10 && expensiveComputation()) |
| | println("doing work...") |
| | else |
| | println("skipping") |
| | } |
| | |
| | evaluate(0) |
| | evaluate(100) |
The expensiveComputation ...
Read now
Unlock full access