Question

I've some issue. I need store a functions into the Map but this functions must have different types of parameters. ie:

Map(1 -> Int => String, 2 -> String => SomeClass) and so on.

So, but types parameters of Function1 should not be Any types. How can I do it? Any ideas. Thanks.

Était-ce utile?

La solution

The scala Map interface only has two type parameters so you can't really do what you want with the scala type system and the standard map.

Since the type system is turing complete you probably can do what you want, possibly by using a similar approach as in the HList http://jnordenberg.blogspot.de/2008/08/hlist-in-scala.html

If you provide what actual problem you try to solve by this strange map we might come up with a solution for you problem. Maybe a type constructor the takes one type and creates a Function1 of two other types, but that's speculation until you state your real problem to solve.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top