Thread overview
Does D have anything like the generators of Python and some other languages?
Aug 29, 2016
A D dev
Aug 29, 2016
Cauterite
Aug 29, 2016
A D dev
Aug 29, 2016
Ali Çehreli
Aug 29, 2016
A D dev
Aug 30, 2016
Meta
Aug 30, 2016
A D dev
August 29, 2016
Hi group,

Does D have anything like the generators of Python and some other languages?

Thanks.

August 29, 2016
On Monday, 29 August 2016 at 21:24:52 UTC, A D dev wrote:
>
> Hi group,
>
> Does D have anything like the generators of Python and some other languages?
>
> Thanks.

Ranges serve some of the purposes that generators are often used for: http://dlang.org/phobos/std_range.html

But you can of course make true coroutine-based generators with fibres: http://dlang.org/phobos/core_thread.html#.Fiber

"fibre" is basically a synonym of "coroutine".
August 29, 2016
On Monday, 29 August 2016 at 21:28:15 UTC, Cauterite wrote:
> Ranges serve some of the purposes that generators are often used for: http://dlang.org/phobos/std_range.html
>
> But you can of course make true coroutine-based generators with fibres: http://dlang.org/phobos/core_thread.html#.Fiber

Thanks. Both sound interesting. Will check.

August 29, 2016
On 08/29/2016 02:50 PM, A D dev wrote:
> On Monday, 29 August 2016 at 21:28:15 UTC, Cauterite wrote:
>> Ranges serve some of the purposes that generators are often used for:
>> http://dlang.org/phobos/std_range.html
>>
>> But you can of course make true coroutine-based generators with
>> fibres: http://dlang.org/phobos/core_thread.html#.Fiber
>
> Thanks. Both sound interesting. Will check.
>

Here is an example of a generator fiber:


http://ddili.org/ders/d.en/fibers.html#ix_fibers.Generator,%20std.concurrency

Ali

August 29, 2016
On Monday, 29 August 2016 at 22:03:35 UTC, Ali Çehreli wrote:
> Here is an example of a generator fiber:

Thanks, will take a look.


August 30, 2016
On Monday, 29 August 2016 at 21:24:52 UTC, A D dev wrote:
>
> Hi group,
>
> Does D have anything like the generators of Python and some other languages?
>
> Thanks.

There's a Generator class in std.concurrency. I haven't used Python all that much so I can't say for certain whether it is the same or not.

https://dlang.org/phobos/std_concurrency.html#.Generator
August 30, 2016
On Tuesday, 30 August 2016 at 00:57:05 UTC, Meta wrote:
> There's a Generator class in std.concurrency. I haven't used

> https://dlang.org/phobos/std_concurrency.html#.Generator


Thanks, Meta.