If your 2nd example compiles, it should compile with a warning: creating a 2-tuple: this may not be what you want
Otherwise it would fail because Some()
doesn't take two parameters. The 1st example should compile because the ->
is explicitly creating the tuple to send as a single parameter to the (outer) Some()
.
When creating a tuple of two elements you have the option of using parentheses and comma (5, true)
, or the arrow 5 -> true
. In most situations the parentheses are optional when using the arrow version.
The arrow can't be used if you want more than 2 elements (i.e. not nested tuples):
'c' -> 'b' -> 'x'
//res0: ((Char, Char), Char) = ((c,b),x)