scala - getter for type parameter with more than one type for case object -


i want have method below code return case object

 sealed trait myconstants[t] extends mytrait[t]    case object extends myconstants[string] {val value = "abc"}    case object b extends myconstants[int] {val value = 10}   val list = seq(a, b) 

i have tried def getvalue[t](value: t): option[myconstants[t]] = list.find(_.value == value) not work.

first compiler has know extends myconstants has value member.

sealed trait myconstants[t] {val value:t} 

now can find() or filter() values match parameter.

def getvalue[a](value: a) = list.find(_.value == value) 

note: you're mixing types in list making getvalue() return type equally complex.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -