how to use first attribute into second attribute from scala case class -


i have created case class this:

case class myclass[t](attname: string, getter: (resultset) => t) 

i intantiate 2 exemple this:

val ex1 = myclass("name", (rs: resultset) => rs.getstring("name")) val ex2 = myclass("age", (rs: resultset) => rs.getint("age")) 

i avoid use 2 time name , age each line. have idea reuse attname in second attribute? thank

something maybe:

class myclass[t](name: string, getter: (resultset, string) => t) {    def getit(rs: resultset): t = getter(rs, name) }  case object myclassname extends myclass[string]("name", _ getstring _) case object myclassage extends myclass[int]("age", _ getint _) 

or

val ex1 = new myclass("name", _ getstring _) val ex2 = new myclass("age", _ getint _) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -