feat: abstract List's toString into generic join method on Sequence
Add `join` and `join(sep)` methods to the `Sequence` class, allowing any sequence to produce a concatenated string of its elements with an optional separator. Refactor `List.toString` to delegate to `join(", ")` with bracket wrapping, removing the manual iteration logic from List. Include new test files for List, Range, and String join behavior, plus runtime error tests for non-string separators.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
var str = "string"
|
||||
|
||||
IO.print(str.join("") == str) // expect: true
|
||||
|
||||
IO.print(str.join(", ")) // expect: s, t, r, i, n, g
|
||||
@@ -0,0 +1 @@
|
||||
"string".join(2) // // expect runtime error: Right operand must be a string.
|
||||
Reference in New Issue
Block a user