Summary: Version of find() which returns the range _before_
what was found
--- Comment #0 from Jonathan M Davis <jmdavisp...@gmail.com> 2010-03-07
04:47:12 PST ---
"abcdefg".find("de") will get you "defg" - everything from the part found
onwards. There is no corresponding function in phobos which would give you the
part _before_ what was found. e.g. "abcdefg".findBefore("de") would return
"abc" (though findBefore may not be the best name).
The until() function is the closest function to something like findBefore(),
but it really isn't the same thing. It will only compare single elements, and
doesn't take multiple needles, just one.
A version of until() that operated on the whole range rather than just the
first element when checking its predicate would definitely work, so maybe it
would be better to alter until() than come up with a new function - or perhaps
we should add a second version of until() that takes a range rather than a
Sentinel. Or we could add both a function which was the counterpart to find()
and a new version of until() which took a range instead of Sentinel - sometimes
it would be desirable to do exactly what find() does except return what was
before what was found, and sometimes it would be nice to have a more flexible
function that just checks the predicate (which probably wouldn't work with
multiple needles like find() does).
Another consideration is that there is no counterpart to until() which returns
what comes after (though a version of it which took a range rather than a
Sentinel would be better IMO). find() is more along the lines of a specialized
version of that.
So, what I'd like to see in phobos would be something along these lines:
1. A function (findBefore() ?) which has basically the same signature as find()
but returns the range before what's being found rather than the range starting
with what's being found.
2. A version of until() which takes a range rather than a Sentinel (though
maybe it would need a different name).
3. A function which has basically the same signature as until() but returns the
range starting with when the predicate is true rather than before.
4. A function which has basically the same signature as the new version of
until() which takes a range rather than a Sentinel but returns the range
starting with when the predicate is true rather than before.
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------