9 Working with laziness
In this chapter
- Understanding the importance of laziness
- Implementing laziness in Kotlin
- Composing with laziness
- Creating a lazy list data structure
- Handling infinite streams
Imagine you’re the bartender in a tiny bar that offers two products: espresso and orange juice. A customer enters and sits. You have two options:
- You prepare an espresso, press an orange juice, bring the two to the customer, and let them choose.
- You ask the customer what they’d like to have, prepare it, and serve it.
In programming terms, in the second case, you’re being lazy, whereas in the first case, you’re being strict. Choosing the best strategy is up to you. This chapter isn’t about morals, but about efficiency.
In this case, there are other ...
Get The Joy of Kotlin now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.