splitter, compilation issue

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Oct 27 18:33:53 PDT 2015


On Wednesday, 28 October 2015 at 00:07:23 UTC, sigod wrote:
> Only removed `filter` from code.

You know, I was just writing an answer for this and I kinda 
changed my mind. Without filter... I think splitter.splitter 
ought to work.

The implementation requires slicing unless you pass it a 
predicate. Only that overload works on minimal forward ranges.

This compiles:

         import std.algorithm;
         import std.array;
         import std.stdio;

         void main(string[] args)
         {
                 auto t = "foo\nbar\ncool---beans"
                         .splitter('\n')
                         .filter!(e => e.length)
                         .splitter!(a => a == "bar")
                 ;
                 writeln(t);
         }

It returns  [["foo"], ["cool---beans"]]; it split it on the "bar" 
line in the middle.

I think that might be basically what you want.


More information about the Digitalmars-d-learn mailing list