-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto should not use implicit conversion functions #45
Comments
Thanks for the suggestion. Have you got a quick Gist to demonstrate the problem in action, or even better something to show the kind of solution that you were thinking of? |
I can try both... I'll use Play for the example, but it's problematic for all other formats as well. import io.fintrospect.formats.Play.Auto._
val js: JsValue = ???
Out {
Service.mk { _: Request =>
Future(js)
}
} You get this compilation error:
My proposed solution would be to introduce a new function-like type: trait ToResponse[-A, +B] {
def apply(a: A): B
}
object ToResponse {
def apply[A, B](f: A => B): ToResponse[A, B] = new ToResponse {
def apply(a: A): B = f(a)
}
} (you might consider extending Now in the def Out[OUT](svc: Service[Request, OUT], successStatus: Status = Status.Ok)
(implicit transform: ToResponse[OUT, R]): Service[Request, Response] And the relevant implicit functions should be wrapped accordingly, for example in implicit def tToJsValue[T](implicit db: Writes[T]): ToResponse[T, JsValue] =
ToResponse { (t: T) =>
JsonFormat.encode[T](t)
} |
Hi,
Currently
io.fintrospect.formats.Auto
uses implicit functions in various methods. E.g.:This can be problematic, for example in cases where one is trying to serialize raw JSON (e.g., Play's
JsValue
). Since in this caseOUT =:= R
, and Fintrospect's built-in implicit conversion competes with the standard library's<:<
(which extendsFunction1
).The workaround for this particular problem is to pass the implicit argument explicitly. But a more general solution would be to introduce a dedicated type for the conversions that take place in
Auto
. This will avoid polluting the implicit scope with a common type and thus won't compete with the standard library (or anything else for that matter).The text was updated successfully, but these errors were encountered: