I surveyed other popular languages having operator overload. This topic is not for voting PEP 584. Just for gathering one of information for making a decision.
I used here instead of ML to update this post by reply.
C++
C++ doesn’t use operator overload for containers much.
- No operator for concatenate vectors
- No operator for union of set
- No operator for merging maps
C#
Like C++, C# doesn’t use operator overload for containers.
Ruby
-
+for concatenateArray: https://docs.ruby-lang.org/en/2.6.0/Array.html#method-i-2B -
|,+for union ofSet: https://docs.ruby-lang.org/en/2.6.0/Set.html#method-i-7C - No operator for merging
Hash: https://docs.ruby-lang.org/en/2.6.0/Hash.html#method-i-merge
Swift
-
+for concatenateArray: https://developer.apple.com/documentation/swift/array/3126935 - No operator for union of
Set: https://developer.apple.com/documentation/swift/set#topics - No operator for merging
Dict:
https://developer.apple.com/documentation/swift/dictionary#topics
Rust
I’m not familiar with Rust so I’m not sure. But it seems implementing traits in core::ops means overloading operator.
- No operator for concat
Vec. Useextend: https://doc.rust-lang.org/std/vec/struct.Vec.html#impl-Extend<T> -
|for union ofHashSet: https://doc.rust-lang.org/std/collections/struct.HashSet.html#impl-BitOr<%26'b%20HashSet<T%2C%20S>> - No operator for merging of
HashMap. Useextend: https://doc.rust-lang.org/std/collections/struct.HashMap.html#impl-Extend<(K%2C%20V)>
Scala
-
++for concatSeq: ref -
|for union ofSet: ref -
++for adding elements from iterator into Set: ref -
++for mergingDefaultMap: ref -
+for adding one or some key: value pairs toDefaultMap(e.g. Similar to Python’sdict.update(key=val, key2=val2)form). ref
Note:
- Scala uses
+for adding one or some elements, and++for adding elements from iterator.
Kotlin
-
+for concatArrayList: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-array-list/index.html -
+for union ofHashSet: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-hash-set/index.html -
+for mergingHashMap: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-hash-map/index.html
Note:
- Kotlin can overload
+but|. So it didn’t mean Kotlin chose+over|. -
-ofHashMaptakes key or iterator of keys, not Map.