One of my methods return a List[(String,Option[Int])]
. I convert it into a Set
calling toSet[(String,Option[Int])]
method of List
question 1 - would this give me a Set[(String,Option[Int])]
?
then I have a case class which can map the data of the Tuple(String,Option[Int])
case class TagCount
case class TagCount (tag:String,count:Int)
Is it possible that using the toSet
method of the List
, I actually get a Set[TagCount]
instead of `Set[(String,Option[Int])]
I notice that toSet
can accept type argument B >: (String,Option[Int])
but I can't figure out how to make TagCount >: (String,Option[Int])
def toSet[B >: A]: Set[B]
You can try:
def foo(in: List[(String, Option[Int])]): Set[TagCount] =
in.toSet.collect {
case (key, Some(c)) => TagCount(key, c)
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments