Generation Size
Let's learn what a generation size is and how the generation size is passed to a generator.
Getting to know generator size
If we take a few elements out of a generator like StreamData.integer/0
, we’ll notice that those integers are simple, that is, they are small integers centered around zero. Now, try to take a few elements out of integer/0
but after discarding a lot of elements:
Executable
Press + to interact
StreamData.integer() |> Stream.drop(100) |> Enum.take(5)
Output
iex> StreamData.integer() |> Stream.drop(100) |> Enum.take(5)
[43, -96, 45, -17, 40]
As we can see, the integers produced by the generator are now more complex—as in, they’re bigger. This suggests that generators produce increasingly more complex terms the more terms they generate. In the case of streaming terms out of a generator, that’s exactly what happens. However, the mechanism behind this is ...