I would like to write a class looking like this:
class Store[+A](dest: Symbol)(implicit c: String => A) extends Action(dest) {
override def update(options: HashMap[Symbol,Any], arg: String): Unit = {
options += ((dest -> c(arg)))
}
}
object Store {
def apply[A](dest: Symbol)(c: String=>A) = new Store[A](dest)(c)
def apply[A](dest: Symbol) = new Store[A](dest)
}
Doing so, I have a few problems:
- Using implicit with strings causes no end of trouble
- Anyway, the system doesn't find the implicit if they are defined in my module, they would need to be defined in the module creating the class
- the second
apply
method of theStore
object just doesn't compile asA
will be erased so the compiler has no way of finding a conversion fromString
toA
How would you create such an object that convert a string to some other type? I wouldn't want the user of the library to enter the type rwice (i.e. by specifying both the type and the conversion function).