Any guide to stream (string) processing in D? | Re: Any python-like generator patterns in D?

jerro a at a.com
Thu Feb 21 08:19:50 PST 2013


D has a concept of iterators, which are similar to python's 
iterators, but more general (python iterators are roughly 
equivalent to input ranges). There are no generator functions in 
D, but you can use fibers to get similar functionality, as Nick 
Sabalausky showed in this thread:

http://forum.dlang.org/thread/jno6o5$qtb$1@digitalmars.com

I've put a simple example that uses a similar approach here:

http://dpaste.dzfl.pl/051751d1

But if you use this, performance will suffer. The last time I 
tried it, fiber based ranges were limited to something like 20 
million iterations (which is similar to python's generators) on 
my machine . Simple ranges, on the other hand, can do billions of 
iterations per second in some cases.


More information about the Digitalmars-d-learn mailing list