These are chat archives for etorreborre/specs2

6th
Dec 2016
Peter Schmitz
@petomat
Dec 06 2016 09:16
Any idea to derive matcher for a sealed base trait given matcher for all leafs?
```
  sealed trait A
  case class B(...) extends A
  case class C(...) extends A
  // given
  def mB(expected: B): Matcher[B] = ???
  def mC(expected: C): Matcher[C] = ???
  // how to automagically derive:
  def mA(expected: A): Matcher[A] = ...
Something with shapeless coproduct decomposition?
Eric Torreborre
@etorreborre
Dec 06 2016 09:19
Isn't shapeless the answer for everything :-)? More seriously I don't really know but I suspect that using Shapeless Generic + marking the subclasses matchers as implicit defs could work
but possibly you would have to introduce a type class for this
trait Matchable[A] {
  def expectedMatcher(a: A): Matcher[A]
}
Peter Schmitz
@petomat
Dec 06 2016 09:21
Yeah, thats pretty close to what I have in mind: Implicit matchers for the case classes... On top of having the coproduct and product machinery. Thanks for the type class hint, makes totally sense.
BTW: It made my day several times because you answered almost instantaneously and your answer always is so helpful. Thanks a lot.
Eric Torreborre
@etorreborre
Dec 06 2016 09:25
I try to do that when I can. 10 minutes later I would have been in a stand-up meeting :-)
Peter Schmitz
@petomat
Dec 06 2016 09:25
Same here in an hour :D