`joinToString` has `truncated: CharSequence = "......
# stdlib
m
joinToString
has
truncated: CharSequence = "..."
as an optional parameter. It would be nice if
String.take(n: Int)
could have the same optional parameter that is appended in case
n
is smaller than the length of the String. Maybe it could also be a different method name, as this would be more a use case for logging/displaying a string similar to joinToString, rather than “working on a string” by using substring for maybe some logical operation on the string. It could be something like
abbreviate
or maybe
cut
a
would you expect
Copy code
"foo bar".take(7, truncated="...") == "foo bar"
"foo bar".take(6, truncated="...") == "foo ba..."
or
Copy code
"foo bar".take(7, truncated="...") == "foo ..."
"foo bar".take(6, truncated="...") == "foo..."
?
m
I would expect the first. Basically the same logic as if I would to “foo bar”.toCharArray().joinToString(“”, limit = 6, truncated=“…”). Maybe the parameter name could imply that it is appended in addition to the specified limit, like
truncatedAppend
or so