Closed kjx closed 8 years ago
I think that this was a consequence of deciding that strings are sequences of single character-strings, rather than of characters. Iterating through a String has always produced Strings. So yes, while
[ "a", "b", "c" ]
and
"abc"
are different (the second has methods like replace(_)with(_)
that the first lacks), they both support iteration, and the iterators both yield the same sequence of single-character strings. So yes, the two lists constructed in the OP are identical.
With the old vararg constructors, the analogous terms would have been
list.with("a", "b", "c")
and
list.withAll "abc"
and they would also have been identical.
If, in contrast, you want a list containing the single string "abc", then with the old interface you would have written list.with "abc"
. With the current interface, we write list [ "abc" ]
. This is exactly analogous to constructing a list containing a single number: list [ 4 ]
.
So, as far as I can see, everything seems to work as one would expect. What's the "issue"?
The issue is I found it confusing.
I guess the advantage of with vs withAll it is it make the creation pattern explicit.
Can we close this? I don't see any action or decision being required.
If Strings are also sequences of strings.
this causes a problem in that neither dynamic checking, or standard static checking, can distinguish between e.g.
and
Is this is problem?
Varargs would make
list "abc"
and list( "a", "b", "c" )` rather different.