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:
Gavin Schulz
2015-01-24 04:45:23 +00:00
parent c65b03ac32
commit 9e20b3935a
9 changed files with 76 additions and 18 deletions
+11
View File
@@ -18,6 +18,17 @@ If it returns `false`, stops iterating and returns `false`. Otherwise, returns
[1, 2, 3].all {|n| n > 2} // False.
[1, 2, 3].all {|n| n < 4} // True.
### **join**(sep)
Returns a string representation of the list. The string representations of the
elements in the list is concatenated with intervening occurrences of `sep`.
It is a runtime error if `sep` is not a string.
### **join**
Calls `join` with the empty string as the separator.
### **map**(transformation)
Creates a new list by applying `transformation` to each element in the