On Friday, 1 June 2018 at 17:00:45 UTC, Xiaoxi wrote:
import std.range;
import std.algorithm;
import std.string;
import std.stdio;
void main()
{
auto s = "1 2 3 4 5 6 7 8 9";
auto iter = s.split(" ").drop(2);
// How to find the unconsumed/not-split part of s here?
// i.e. "3 4 5 6 7 8 9" NOT ["3", "4", "5", "6", "7", "8",
"9"]
// s[??? .. $] <- what goes here?
}
split is just an example, it's a generic question if you chain
multiple lazy functions and then consume a part of the data...
how do you know how to slice the original buffer to point to
the unconsumed data? Imagine the chain could be quite long
s.one.two.three.four.five.six.seven()
You don't really want to lazily add the inverse of all the
functions and they might even be destructive so it might not be
possible in all cases.
Split is already destructive, as you loose the whitespaces. In
this special case, maybe by
iter.join(" ");
https://dlang.org/library/std/array/join.html
In case the the separator can't be known in advance, I would
choose to store it somehow... Maybe by
https://dlang.org/library/std/algorithm/searching/find_split.html
?