Splitting Ranges using Lambda Predicates

monarch_dodra via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 11 05:40:11 PDT 2014


On Wednesday, 11 June 2014 at 11:42:42 UTC, Artur Skawina via 
Digitalmars-d-learn wrote:
> On 06/11/14 00:31, "Nordlöw" via Digitalmars-d-learn wrote:
>>> Either way, it shouldn't be too hard to implement. Base it 
>>> off "splitter!pred", which is actually quite trivial. AFAIK, 
>>> your
>> 
>> What do you mean by basing it off splitter!pred - should I 
>> start with some existing splitter algorithm in Phobos or start 
>> from scratch?
>
> Starting from scratch is actually not a bad idea, at least for 
> this kind
> of trivial functionality. A working version can be written in 
> less time
> than copying, analyzing and modifying another implementation...
>
> ...
>
> artur

I don't know about "starting from scratch" entirely. Maybe not 
copy paste, but it always helps to have a reference 
implementation.

For example, you should avoid "countUntil" and "takeExactly" when 
dealing with strings, since these are not O(1) operations, and 
don't actually return string slices. EG:
string s = "someGGGreatVariableName".slicer().front;
Error: cannot implicitly convert expression 
(slicer("someGGGreatVariableName").front()) of type Result to 
string

That's why the splitter code uses the more verbose "r.length - 
r.find!pred".


More information about the Digitalmars-d-learn mailing list