simulacrum
simulacrum copied to clipboard
Add support for operators that return values of the type of the type class parameter
For a given type class F[T]
, Simulacrum can currently generate operators for all methods of the shape def f(t:T): X
. It would be nice if it also supported operator generation for methods of the shape def f(): T
.
As a concrete example, consider the following type class:
trait Decoder[T] {
def decode(s: String): T
}
It would be convenient for String
to be enriched with a decode
operator, enabling code such as "123".decode[Int]
(provided a Decoder[Int]
is in scope).
A possible issue would be that, in order to support subtyping of type classes, Simulacrum would need to generate 2 classes for each enhanced type - Decoder.StringOps
and Decoder.AllStringOps
in our example, for instance.
See this gitter thread for additional context.