Search code examples
ceylon

Infinite iterable generator in Ceylon


Is there an easy way in Ceylon to create an infinite iterable which generates each element by calling the same given no-args function? In other words, does the language module offer an equivalent to Java 8's Stream.generate(Supplier<T>)?


Solution

  • Here's what I came up with:

    {Value+} generator<Value>(Value() generate) => {generate()}.cycled;
    

    This works because {generate()} is lazy.