In one of my previous post i tired to make python like generator in java using Supplier
function and IntStream
. That didnt fully behaved like a generator. So tried implementing this time using custom Iterator
for lazy evaluation of the items in the collections and using a Thread
to produce the items that will be yield
when calling the generator.
in this repl you can execute the generator named InfiniteGenerator
which extended an abstract
class Generator<T>
which in turn implements Iterable<T>
to implement a custom iterator of a given type. Any class implementing Generator<T>
class will be able to act like an generator if a given implementation that provides with items.