The ordering of implicit seems to matter when using shapeless. Look at the example code below where it will not work.
import shapeless._ case class Userz(i: Int, j: String, k: Option[Boolean]) object r { def func(): Userz = { val a = Userz(100, "UserA", Some(false)) val b = Userz(400, "UserB", None) val genA = Generic[Userz].to(a) val genB = Generic[Userz].to(b) val genC = genA zip genB val genD = genC.map(Mergerz) val User = Generic[Userz].from(genD) return User } } object Mergerz extends Poly1 { implicit def caseInt = at[(Int, Int)] {a => a._1 + a._2} implicit def caseString = at[(String, String)] {a => a._1 + a._2} implicit def caseBoolean = at[(Option[Boolean], Option[Boolean])] {a => Some(a._1.getOrElse(a._2.getOrElse(false)))} } r.func() And the code below which will work
import shapeless._ case class Userz(i: Int, j: String, k: Option[Boolean]) object Mergerz extends Poly1 { implicit def caseInt = at[(Int, Int)] {a => a._1 + a._2} implicit def caseString = at[(String, String)] {a => a._1 + a._2} implicit def caseBoolean = at[(Option[Boolean], Option[Boolean])] {a => Some(a._1.getOrElse(a._2.getOrElse(false)))} } object r { def func(): Userz = { val a = Userz(100, "UserA", Some(false)) val b = Userz(400, "UserB", None) val genA = Generic[Userz].to(a) val genB = Generic[Userz].to(b) val genC = genA zip genB val genD = genC.map(Mergerz) val User = Generic[Userz].from(genD) return User } } r.func() My question is, why does the order matters? I already tried importing the implicits which doesn't work.