Thread overview | ||||||
---|---|---|---|---|---|---|
|
February 19, 2019 Generators in D | ||||
---|---|---|---|---|
| ||||
Hi there, is the concept of generators (like in Python, using yield) available in D? If so, where can I find information? Regards |
February 19, 2019 Re: Generators in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew_Blake | On Tuesday, 19 February 2019 at 18:37:22 UTC, Matthew_Blake wrote: > Hi there, > > is the concept of generators (like in Python, using yield) available in D? If so, where can I find information? > > Regards I do not know python well, but do you search for this one? http://ddili.org/ders/d.en/fibers.html Kind regards Andre |
February 19, 2019 Re: Generators in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew_Blake | On Tuesday, 19 February 2019 at 18:37:22 UTC, Matthew_Blake wrote: > Hi there, > > is the concept of generators (like in Python, using yield) available in D? If so, where can I find information? > > Regards Generally speaking, things that are generators in Python are implemented as ranges [1] in D. If ranges aren't a good fit for your problem, though, you can also use opApply [2] and std.concurrency.Generator [3]. [1] https://tour.dlang.org/tour/en/basics/ranges [2] https://dlang.org/spec/statement.html#foreach_over_struct_and_classes [3] https://dlang.org/phobos/std_concurrency.html#.Generator |
February 19, 2019 Re: Generators in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Tuesday, 19 February 2019 at 18:56:01 UTC, Paul Backus wrote:
> On Tuesday, 19 February 2019 at 18:37:22 UTC, Matthew_Blake wrote:
>> Hi there,
>>
>> is the concept of generators (like in Python, using yield) available in D? If so, where can I find information?
>>
>> Regards
>
> Generally speaking, things that are generators in Python are implemented as ranges [1] in D. If ranges aren't a good fit for your problem, though, you can also use opApply [2] and std.concurrency.Generator [3].
>
> [1] https://tour.dlang.org/tour/en/basics/ranges
> [2] https://dlang.org/spec/statement.html#foreach_over_struct_and_classes
> [3] https://dlang.org/phobos/std_concurrency.html#.Generator
Thank you both! I'll look into it
|
Copyright © 1999-2021 by the D Language Foundation