On Sunday, 14 October 2012 at 20:03:52 UTC, Mehrdad wrote:
On Sunday, 14 October 2012 at 19:26:37 UTC, Peter Alexander wrote:
On Sunday, 14 October 2012 at 09:50:20 UTC, Mehrdad wrote:
Why doesn't code like this work?

chain(repeat("a").take(5), repeat("b").take(5)).splitter("b");

chain doesn't support slicing (and isn't a narrow string), so you can't split it using this function.

Yup, but why does it need slicing?

Well, for example:

splitter("hello world", ' ')

gives

["hello", "world"]

The splits are slices of the original range.

splitter could allocate new ranges, but if you want that behaviour then it's better to specify it manually:

chain(repeat("a").take(5), repeat("b").take(5)).array().splitter("b");

That works, giving:

[["a", "a", "a", "a", "a"], [], [], [], [], []]

I wonder if a better design for splitter would automatically allocate an array when the input range doesn't support slicing?

Reply via email to