I know some people don’t like the fact that + is overloaded for concatenation. But since String + &str is already implemented, I think that ship has sailed. It is no longer possible to take this out and add another concatenation operator.
I propose that Add be implemented for the String + String case as well. It might not be a big deal in most cases like a + &b - this is not too much extra typing. Where it’s more annoying is in cases like .fold1(String::add) with fold1 from itertools which doesn’t work. Here typing .fold1(|x, y| x + &y) is a lot longer and more complicated. I went ahead and just did this:
pub trait Concatenable {
fn concat(self, other: Self) -> Self;
}
impl Concatenable for String {
fn concat(mut self, other: String) -> String {
self.push_str(&*other);
self
}
}
so I could do .fold1(String::concat) whenever I want to. This is much more readable, it has three parts, one of which is a path separator. On the other hand, the closure has 9 separate elements that I have to read, so I have to slow down and check that it does what I think it does.
I think there is no downside to actually doing this and the implementation is pretty trivial. Are there any arguments against it?