- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Building a map from an array of tuple.
Thu, 2012-01-19, 11:33
Dear all,
I am trying to build a immutable map from an array of tuple, however I can't find the right syntax.
Map companion object contains an apply method to build from a varargs list of tuples, but I get an error.
scala.collection.immutable.Map(result);
error: type mismatch;found : Array[(Double, com.gottex.gottware.common.datamodels.finance.math.termstructure.InterestRate)] required: (Double, com.gottex.gottware.common.datamodels.finance.math.termstructure.InterestRate)scala.collection.immutable.Map(result);
Why ? :)
Thank you very much Best regards
I am trying to build a immutable map from an array of tuple, however I can't find the right syntax.
Map companion object contains an apply method to build from a varargs list of tuples, but I get an error.
scala.collection.immutable.Map(result);
error: type mismatch;found : Array[(Double, com.gottex.gottware.common.datamodels.finance.math.termstructure.InterestRate)] required: (Double, com.gottex.gottware.common.datamodels.finance.math.termstructure.InterestRate)scala.collection.immutable.Map(result);
Why ? :)
Thank you very much Best regards
Thu, 2012-01-19, 12:01
#2
Re: Building a map from an array of tuple.
yourTuple2Collection.toMap
to call the vararg method, tell the compiler you want to apply an array as a vararg param by adding this weird smiley:
:_*
Map(Array((1,2)):_*)
-------- Original-Nachricht --------
> Datum: Thu, 19 Jan 2012 11:33:12 +0100
> Von: Edmondo Porcu
> An: scala-user
> Betreff: [scala-user] Building a map from an array of tuple.
> Dear all,
>
> I am trying to build a immutable map from an array of tuple, however I
> can't find the right syntax.
>
> Map companion object contains an apply method to build from a varargs list
> of tuples, but I get an error.
>
> scala.collection.immutable.Map(result);
>
> error: type mismatch;
> found : Array[(Double,
> com.gottex.gottware.common.datamodels.finance.math.termstructure.InterestRate)]
> required: (Double,
> com.gottex.gottware.common.datamodels.finance.math.termstructure.InterestRate)
> scala.collection.immutable.Map(result);
>
> Why ? :)
>
> Thank you very much
> Best regards
scala.collection.immutable.Map(result: _*)
-jason