0

A simple example:

class A
class B
class C

object testobject {
  val a = new A
  implicit def b(a:A):B = new B
  implicit def c(b:B) = new C
  val b:B = a
  val c:C = a 
}

The last line doesn't compile. We have A=>B and B=>C implicit conversions defined but that doesn't infer A=>C.

It would be really nice to be able to have layers of implicit conversions work.

My particular problem. too long to post fully is actually from a web framework. I want to do something like:

A => Secure[A] => Format[A]

with the following

implicit def secure[A](a:A):Secure[A] = ???
implicit def format[A](sec:Secure[A]):Format[A] = ???

So I want to handle security and formatting through implicit magic, and only secured outputs can be formatted.

Has anybody found any tricks to make this, or something like this work?

triggerNZ
  • 4,221
  • 3
  • 28
  • 34

1 Answers1

1

This question is answered quite well here:

How can I chain implicits in Scala?

In short Scala does not chain implicit conversions, it only looks for direct conversion A => B. However, using additional implicit parameters the desired effect can be achieved.

Community
  • 1
  • 1
yǝsʞǝla
  • 16,272
  • 2
  • 44
  • 65