There's also a minus part (-), which would be very stretching to include in the Array APIs.
Not all collections can be concatenated, or even mutated. A CollectionOfOne is one good example that doesn't allow arbitrary concatenation.
Even then, chances are, you don't want/need both collections have the same type. We also have + on RangeReplaceableCollection.
In Swift, there's a distinction between not having an array (nil) and having one that is empty ([]). A good rule-of-thumb is that, if you do nothing when it's optional, you can just take non-optional value, and let the caller deal with optional.
Protocols in Swift have semantic meaning They are not just groups of syntax.
The documentation for AdditiveArithmetic states:
The AdditiveArithmetic protocol provides a suitable basis for additive arithmetic on scalar values, such as integers and floating-point numbers, or vectors. You can write generic methods that operate on any numeric type in the standard library by using the AdditiveArithmetic protocol as a generic constraint.
Array is not a scalar nor, in general, a mathematical vector (although it may be used to implement vector values such as matrices or tensors). Adding two matrices is a different operation to concatenating two Arrays. A similar argument applies to String, which also has a concatenating + operator.
As another poster said, Swift protocols aren't just bags of syntax. Conforming to a protocol is a promise to maintain its semantics. The problem is that there are two forms of "+". One is a customization point for AdditiveArithmetic; the other is a set of extension methods for RangeReplaceableCollection. The Array type uses the ones from RRC, and said choice is incompatible with the operator in AA.
Even if the RRC versions weren't present in Array, what would an AA version do when the operands have different element counts? (This assumes that you want an AAArray to add corresponding elements together, and not concatenate the operands.)
What’s the point of unifying the + operator? They mean totally different in each context. And it’s not like we have a lot of things that can conform to both.
Yeah you’re right. What I meant to say is that Arrays don’t in general model mathematical vectors. So Array’s + operator doesn’t mean “addition”, it means “concatenation” - and they are very different things.
For example, addition is commutative, so a + b must give the same result as b + a. Array’s + operator doesn’t do that.