-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add String::concat_view #1249
Conversation
Pull Request Test Coverage Report for Build 3978Details
💛 - Coveralls |
@@ -64,6 +64,22 @@ pub fn String::concat( | |||
buf.to_string() | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the rationale to make it a plain function istead of a method?
How about: pub(open) trait IterString {
iter(Self) -> Iter[String]
}
pub fn concat[T : IterString](strings : T, separator~ : String = "") -> String {
let buf = StringBuilder::new()
let mut str : String? = None
for s in strings {
if str.is_empty().not() {
buf.write_string(str.unwrap())
buf.write_string(separator)
}
str = Some(s)
} else {
if str.is_empty().not() {
buf.write_string(str.unwrap())
}
}
buf.to_string()
}
test {
inspect!(concat(([] : Array[String])), content="")
inspect!(concat(["a", "b", "c"]), content="abc")
inspect!(concat(["a", "b", "c"], separator="|"), content="a|b|c")
inspect!(concat(["a", "b", "c"][1:], separator="|"), content="b|c")
inspect!(
concat((["a", "b", "c"] : FixedArray[String]), separator="|"),
content="a|b|c",
)
} |
It is a quite feasible plan |
We are now considering moving it to |
|
String::concat
takeArrayView[T]
#1148