I have a piece of code in implicit class -
implicit class Path(bSONValue: BSONValue) {
def |<[S, T <:{def value:S}] = {
bSONValue.asInstanceOf[T].value
}
}
The problem is if I want to call |<
method after BSONValue I need to call with .
.
e.g
(doc/"_id").|<[String,BSONString]
The problem is without .
scala raises error because it does not allow type parameter method with infix notation. So always I have to wrap doc/"_id"
portion with ()
.
Is their any way of using type parameter method without .
eg
doc/"_id"|<[String,BSONString]
All types
T
that you want to get out ofBSONValue
s will probably have a companion object with the same name. You could use that companion object as an intuitive placeholder for the type that you actually want to get. Something along these lines:This allows you to use infix syntax, because all those things are ordinary values.
Still, only because it's possible, it doesn't mean that you have to do it. For instance, I wouldn't know what to expect from a
|<
-operator. Many other people also wouldn't know what to do with it. They'd have to go and look it up. Then they would see this signature:I can imagine that the vast majority of people (myself in one week included) would not be immediately enlightened by this signature.
Maybe you could consider something more lightweight:
It seems to do roughly the same as the
|<
operator, but with much less magic going on.