Problem: I have some case classes and for every case class I have to run one simple function that return same instance of case class. so for every case class I have to implement same function each time even though, function has same functionality. Is there a SCALA way of iterating over case class type.
object SampleCaseClasses {
case class a(elem1: String, elem2: Int)
case class b(elem3: String, elem4: Int)
case class c(elem5: String, elem6: Int)
case class d(elem7: String, elem8: Int)
case class e(elem9: String, elem10: Int)
case class f(elem10: String, elem12: Int)
case class g(elem11: String, elem14: Int)
}
import SampleCaseClasses.{a, b}
def getProperAddress[a](host:String,port:Int): SampleCaseClasses.a ={
a(host.toUpperCase,port+1)
}
def getProperAddress[b](host:String,port:Int): SampleCaseClasses.b ={
b(host.toUpperCase,port+1)
}
def getProperAddress[a]is unnecessary, just remove the[a]it is not doing what you think is doing.