Yield from function?
pineapple via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jan 30 03:09:39 PST 2017
On Monday, 30 January 2017 at 11:03:52 UTC, Profile Anaysis wrote:
> I need to yield from a complex recursive function too allow
> visualizing what it is doing.
>
> e.g., if it is a tree searching algorithm, I'd like to yield
> for each node so that the current state can be shown visually.
>
> I realize that there are several ways to do this but D a yield
> version without additional threads would be optimal. I don't
> need concurrency or speed, just simple.
You may be able to use Generator in std.concurrency for this:
https://dlang.org/phobos/std_concurrency.html#.Generator
You could also rephrase your algorithm as a range, which would
not involve concurrency but may be unintuitive to implement. In
this case you would likely have to use a stack or queue rather
than a recursive function.
Is it an option to just accumulate the information regarding your
algorithm in a separate data structure and then analyze it after
the algorithm is complete, or has recorded some number of entries?
More information about the Digitalmars-d-learn
mailing list