Splitting Ranges using Lambda Predicates

Artur Skawina via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 11 11:20:24 PDT 2014


On 06/11/14 16:05, monarch_dodra via Digitalmars-d-learn wrote:
> Well, (IMO) it's a problem with no real solution. But for what it's worth, most (if not all) of the algorithms in the standard lib know how to handle strings efficiently and correctly (split, find, etc...). Things only start getting funny once you start mixing indexing and element counts.

If the recommended approach for writing a really trivial string transformation
is to copy and modify ~60 lines of std lib code then something is very wrong.
The consequence is that such code will often end up being eager, as it's much
easier to write it that way... That is why, after seeing your solution, I wrote
the most compact lazy version I could think of - let's not scare people away
from using ranges.

AFAIUI the OP basically wanted a version of splitter that does not eat the
separators and a predicate that keeps around previous state. The latter can
already be achieved via a lambda, so the missing bit is an optional splitter
template parameter (eg consume=false). So at least in this case the problem
could be easily handled.

artur


More information about the Digitalmars-d-learn mailing list