This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Building a map from an array of tuple.

2 replies
edmondo1984
Joined: 2011-09-14,
User offline. Last seen 28 weeks 3 days ago.
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
Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
Re: Building a map from an array of tuple.
On Thu, Jan 19, 2012 at 11:33 AM, Edmondo Porcu <edmondo.porcu@gmail.com> wrote:
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 ? :)

scala.collection.immutable.Map(result: _*)
-jason
H-star Development
Joined: 2010-04-14,
User offline. Last seen 2 years 26 weeks ago.
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

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland