I like lazy data structures, so I was curious about how they could
be implemented in Erlang. Actually, I have found that is quite
easy. In order to understand how they work only a little understanding
of functional programming is needed.
Let’s see a basic example.
Let’s see it in action.
Basically, the clue is to keep the state as a tuple with its first
term being the current value and the second one a function which
encloses the next execution of the generator for the tail. The
potential for the next execution is retained in this clousure.
Another example with infinite values.
And its execution.
As its title denotes this post has been quite short.