How to create an Array for Tuples in Scala?

145 Views Asked by At

Im trying to create an empty Array to store coordinates of an object in an Tuple which is then stored in an Array.

When I try:

var walls = Array[Tuple2]()

Im getting this error message:

kinds of the type arguments (Tuple2) do not conform to the expected kinds of the type parameters (type T).
[error] Tuple2's type parameters do not match type T's expected parameters:
[error] class Tuple2 has two type parameters, but type T has none
[error]         var walls = Array[Tuple2]()

Is there any possibility to do this?

2

There are 2 best solutions below

0
TamZ On

Okay I found a way:

var walls = Array[(Int, Int)]()
0
Dmytro Mitin On

Tuple2 is a type constructor (of kind [*, *] => *).

Array is a type constructor too (of kind [*] => *).

You have to apply Tuple2 to two types (of kind *) in order to make it suitable as an argument of Array.

That's why Array[(Int, Int)] aka Array[Tuple2[Int, Int]] is working while Array[Tuple2] is not.