문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top