Why and how is Some(1, 2, 3) a valid expression?

Maybe it is general knowledge but I’ve just found that Some(1, 2, 3) is valid and it is an Option[(Int, Int, Int)].

Why is it so?

Where is the magic that makes it possible?

Thanks !!!

Juan Manuel

2 Likes

Well, I never … you learn something new every day.

I was curious and found this: https://contributors.scala-lang.org/t/lets-drop-auto-tupling/1799/24.

The moral of the story is, don’t get too attached to this…

2 Likes

Is called auto-tupling, it is just more sugar syntax. And is deprecated now because it is confusing for most folks.

3 Likes

Good advice in general.

For this feature specifically, it seems possible one can have a future together and develop a deep relationship in which you’ve forgotten which stuff is yours and which stuff belongs to auto-tupling and multi-arg infix.

The linked threads, tickets, and pull requests demonstrate the relationship history and associated baggage. There is a recent discussion. The unresolved issue is efficient and pleasant

buf += (42, 27)  // addAll
map += (42, 27)  // addOne(42 -> 27)

You’ll always be able to write Some apply (42, 27), or

scala> extension (x: Some.type) infix def of[A](a: A): Some[A] = Some(a)
def of(x: Some.type)[A](a: A): Some[A]

scala> Some of (1,2)
val res2: Some[(Int, Int)] = Some((1,2))

Since the feature has been under discussion for 6-14 years, probably Scala won’t meet its climate change goals by 2030 and the atmosphere will remain heated.

2 Likes

Thanks for all the answers !!

1 Like