October 28, 2015 Re: splitter, compilation issue | ||||
---|---|---|---|---|
| ||||
Posted in reply to sigod | On Tuesday, 27 October 2015 at 22:56:07 UTC, sigod wrote: > On Tuesday, 27 October 2015 at 22:33:32 UTC, Adam D. Ruppe wrote: >> On Tuesday, 27 October 2015 at 22:18:55 UTC, sigod wrote: >>> P.S. Maybe I should repost my question on SO? I really thought it was a bug, so I posted it here. >> >> You could, but I'd say the same thing there > > I don't expect different answer there. Main idea is to increase language presence and therefore popularity. > > I saw someone (I think it was Martin Nowak) somewhere saying that maybe we should move questions from Learn forum to SO. > >> or just stick in .array somewhere to do an easy, generic solution > > Which completely works in this case. Since I'm writing just a code generation tool, which I'll need to use just a few times. Posted it here: http://stackoverflow.com/q/33380674/944911 Only removed `filter` from code. |
October 28, 2015 Re: splitter, compilation issue | ||||
---|---|---|---|---|
| ||||
Posted in reply to sigod | 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.
|
Copyright © 1999-2021 by the D Language Foundation