How to convert data in a Set[Tuple2] into a case class

Manu Chadha

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]
cchantep

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to convert a list of case class data to List of string data?

How to convert case class into string

how to convert a list of string to case class?

How to convert the Scala case class definition to Haskell?

How to convert values of a case class into Seq?

How to convert query result to case class?

How to convert nested case class into UDTValue type

How to convert case class RDD to RDD[String]?

How to convert data class to map

How to convert parquet data to case classes with spark?

Scala shapeless: how to convert a hlist.Mapper to a case class?

How to convert spark SchemaRDD into RDD of my case class?

how to convert members of case class in Scala to List of Objects in Java

How to convert Row of a Scala DataFrame into case class most efficiently?

How to convert a case-class-based RDD into a DataFrame?

How to convert a json with a single value to a case class using play json

How to read json file and convert to case class with Spark and Spray Json

how to convert a RDD to other RDD using case class property?

How to convert Date column format in case class of Scala?

how to convert class in scala into Algebraic Data Types?

How convert Object String to Data Class in kotlin

How to convert a Data Class to ByteBuffer in Kotlin?

How to Convert PHP class to json data?

How to convert Firestore document data into a Class

How to convert <class 'bytes'> data in tuple in python?

How to convert firebase data (snake_case) to Java object (camelCase)

Swift: How should I transfer data to other class in this case?

Convert case class with Options to case class without Options

Convert a Map to a Data Class