replaceFirst, findPieces, and takeExactly
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sat Jan 22 13:27:42 PST 2011
OK, I added replaceFirst:
http://d-programming-language.org/cutting-edge/phobos/std_array.html#replaceFirst
http://www.dsource.org/projects/phobos/changeset/2365
I've also added two crucial abstractions that finally quench my many
sleepless nights following my Boostcon keynote. Back then people said
that STL's find() is better than D's find() because the former returns
an iterator that can be combined with either the first iterator to get
the portion before the match, or with the last iterator to get the
portion starting at the match. D's find() only gives you the portion
after the match.
The first abstraction is the takeExactly() function:
http://d-programming-language.org/cutting-edge/phobos/std_range.html#takeExactly
That function allows you to pick a determined number of elements from a
range, assuming the range is never shorter than that. That sounds a bit
obscure, but plays a pivotal role in findParts() (which is the name I
settled on for the equivalent of Python's partition()):
http://d-programming-language.org/cutting-edge/phobos/std_algorithm.html#findParts
There are many nice things about findParts() that make it feel whole:
all parts have lengths, their types are the best possible given the
input, and the amount of information conveyed is maximized.
The implementations of findParts and takeExactly are simple and elegant too:
http://www.dsource.org/projects/phobos/changeset/2365
Andrei
More information about the Digitalmars-d
mailing list