Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Is it an issue need to be resolved? += (("a", 1)) #20066

dongxuwang started this conversation in General Discussion
Discussion options

For += with tuple, why I have to add () to wrap the tuple value

import collection.mutable.ArrayBuffer
val x: ArrayBuffer[(String, Int)] = ArrayBuffer(("a", 1))
// x += ("b", 2) // this wouldn't work
x += (("b", 2))
You must be logged in to vote

Replies: 2 comments

Comment options

Apparently, we untuple tuple arguments of infix operations if the function does not consist only of unary alternatives.

trait Buffer1[A]:
 def += (elem: A): Buffer1[A]
val b1: Buffer1[(String, Int)] = ???
b1 += ("a", 1) // Ok
trait Buffer2[A]:
 def += (elem: A): Buffer2[A]
 def += (elem1: A, elem2: A): Buffer2[A]
val b2: Buffer2[(String, Int)] = ???
b2 += ("b", 2) // Error
/** Should we tuple or untuple the argument before application?
* If auto-tupling is enabled then
*
* - we tuple n-ary arguments where n > 0 if the function consists
* only of unary alternatives
* - we untuple tuple arguments of infix operations if the function
* does not consist only of unary alternatives.
*/
def needsTupledDual(funType: Type, pt: FunProto)(using Context): Boolean =
You must be logged in to vote
0 replies
Comment options

Since the alternative Growable#+= is deprecated, it would be handy if it were ignored for purposes of infix untupling. Hopefully it can be removed someday.

The current nice syntax is x += "b" -> 2.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /