Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
StringLike.linesWithSeparators gives wrong result for the empty string #9773
According to http://www.scala-lang.org/api/2.11.8/index.html#scala.collection.immutable.StringLike@linesWithSeparators:Iterator[String], "The number of strings returned is one greater than the number of line end characters in this string. For an empty string, a single empty line is returned."
But in fact,
Either documentation or implementation has to be fixed. On one hand, the documented behavior is what I expected before reading, but on the other there probably are applications/libraries relying on the current one...
Imported From: https://issues.scala-lang.org/browse/SI-9773?orig=1
@som-snytt said (edited on May 12, 2016 6:02:47 PM UTC):
The doc is plain wrong, since "a\nb" and "a\nb\n" are both two elements.
However, the impl is also wrong because it ought to work like split, except retaining the separators in the preceding element.