Strange there's no appending method on immutable arrays apart from using a plus operator.
+ is the outlier, isn’t it. There’s no similar methods on Sets or Dictionaries either, though NSArray and NSSet and NSDictionary have some.
If I were to assign meaning to this, it would be that the lack of copy-and-change methods encourages people to use mutation, which is often more efficient / easier to optimize. But sometimes you really do just want “the same dictionary with one value removed” or whatever.
Speaking of, given that you can't look up operator definitions anymore, where are these overloads defined? I didn't think they were in the standard library!
(1...2) + [3, 4] ["🍔"] + CollectionOfOne("🍟")
These come from
RangeReplaceableCollection, which offers a few overloads:
static func +<Other>(lhs: Self, rhs: Other) -> Self where Other : Sequence, Self.Element == Other.Element
static func +<Other>(lhs: Other, rhs: Self) -> Self where Other : Sequence, Self.Element == Other.Element
static func +<Other>(lhs: Self, rhs: Other) -> Self where Other : RangeReplaceableCollection, Self.Element == Other.Element
The first two handle arbitrary
Sequences on either side of the
+ (which is what allows your first example to work —
ClosedRange is a
Sequence, but not a
RangeReplaceableCollection), and the last handles combining two
This might be a reasonable place to start adding -ing methods to.