On Wednesday, 10 September 2014 at 22:29:55 UTC, Ali Çehreli wrote:
    assert("foo\nbar\n"
           .splitter(newline)
           .filter!(a => !a.empty)
           .equal([ "foo", "bar" ]));
}

Ali

Ok, great.

So I got.

auto byLine(Range)(Range input) if (isForwardRange!Range)
{
    import std.algorithm: splitter;
    import std.ascii: newline;
    static if (newline.length == 1)
    {
        return input.splitter(newline.front);
    }
    else
    {
        return input.splitter(newline);
    }
}

unittest
{
    import std.algorithm: equal;
    assert(equal("a\nb".byLine, ["a", "b"]));
}

One thing still:

Is my optimization for newline.length == 1 unnecessary or perhaps even wrong?

Reply via email to