Why scala Tuple productIterator return type Iterator[Any] ?
For example if Tuple3 or Product3 productIterator following definition
def productIterator[T1<:X,T2<:X,T3<:X,X] = Iterator(_1,_2,_3)
following Expression can return Iterator[java.lang.Number]
(BigInt(1),new java.lang.Long(2),new java.lang.Float(3)).productIterator
But current scala version (2.9.1) is not so . Is there a reason for something ?
% scala3 -Xexperimental
Welcome to Scala version 2.10.0.rdev-4056-2011-12-21-g69ed0a9 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).
Type in expressions to have them evaluated.
Type :help for more information.
scala> case class Foo[T1 <: java.lang.Number, T2 <: java.lang.Number](s: T1, t: T2)
defined class Foo
scala> Foo[java.lang.Integer, java.lang.Long](5, 5L)
res1: Foo[Integer,Long] = Foo(5,5)
scala> res1.productIterator _
res2: () => Iterator[Number] = <function0>
UPDATE
It is the least upper bound of the (unerased) types of the product elements. For instance in a Product[T, U, V]
it's the same type as an expression
if (cond1) x1: T else if (cond2) x2: U else x3: V
or the type of the List in
List(x1: T, x2: U, x3: V)
In the repl look at the inferred type of f in
def f[T] = List(null: List[T], null: Set[T], null: Iterator[T])
to see what I mean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With