When we talk about being lazy in our daily activity, we might think about something we don't do but we actually have to do. Or, we might put off doing something just because we are lazy. In functional programming, laziness is analogous to our laziness in daily activities. The execution of particular code is deferred due to the concept of laziness thinking. In Chapter 5, Querying Any Collection Easily with LINQ we mentioned that LINQ implemented deferred execution when querying data from a collection.
The query will be executed only when it's enumerated. Now, let's discuss the laziness concept we can use in the functional approach.
In the .NET framework, there are some techniques to enumerate a collection of data, such as array and List<T>
. However, implicitly, they are eager evaluations since in an array, we have to define its size first and then fill in the allocated memory before we use it. List<T>
has a similar concept compared to array...