I'm new to Scala...
Anyway, I want to do something like:
val bar = new Foo("a" -> List[Int](1), "b" -> List[String]("2"), ...)
bar("a") // gives List[Int] containing 1
bar("b") // gives List[String] containing "2"
The problem when I do:
class Foo(pairs: (String, List[_])*) {
def apply(name: String): List[_] = pairs.toMap(name)
}
pairs
is gonna be Array[(String, List[Any]) (or something like that) and apply()
is wrong anyway since List[_]
is one type instead of "different types". Even if the varargs * returned a tuple I'm still not sure how I'd go about getting bar("a")
to return a List[OriginalTypePassedIn]
. So is there actually a way of doing this? Scala seems pretty flexible so it feels like there should be some advanced way of doing this.