concept laziness in category kotlin

appears as: laziness, laziness
Functional Programming with Kotlin

This is an excerpt from Manning's book Functional Programming with Kotlin.

The catches function is a general-purpose function we can use to convert from an exception-based API to an Option-oriented API. This uses a non-strict or lazy argument, as indicated by the () → A as type of a. We’ll discuss laziness in much greater detail in chapter 5, but for now all we need to know is that the lazy parameter can be evaluated by calling invoke(), or with the equivalent () shorthand notation. In other words, the invocation could have been made as a.invoke() or a().

It turns out that we can accomplish this kind of automatic loop fusion through the use of non-strictness (or, less formally, laziness). In this chapter, we’ll explain exactly what this means, and we’ll work through the implementation of a lazy list type that fuses sequences of transformations. Although building a “better” list is the motivation for this chapter, we’ll see that non-strictness is a fundamental technique for improving on the efficiency and modularity of functional programs in general.

The Joy of Kotlin

This is an excerpt from Manning's book The Joy of Kotlin.

This construction avoids using a nullable type. But it offers absolutely no benefit compared to by lazy except when initialization should be done externally, such as when using a dependency injection framework while working with properties. Note that constructor-based dependency injection should always be preferred because it allows using immutable properties. As you’ll see in chapter 9, there’s much more to learn about laziness.

9.7 Strictness versus laziness

Some languages are said to be lazy; others are strict. Generally, this is about how languages evaluate function or method arguments. But in reality, all languages are lazy because laziness is the true essence of programming.