I am trying to convert Map[String, AttributeValue]
to Scala objects. AttributeValue
represents data in DynamoDB. FromAttributeValue
in the below stub is used to convert basic cases
Following is code stub:
trait FromMap[L] {
def apply(m: Map[String, AttributeValue]): Option[L]
}
object FromMap extends LowerPriorityFromMapInstances {
implicit val hnilFromMap: FromMap[HNil] = (m: Map[String, AttributeValue]) => Some(HNil)
implicit def hconsFromMap0[K <: Symbol, V, T <: HList](implicit
witness: => Witness.Aux[K],
fromAttributeValue: => Lazy[FromAttributeValue[V]],
fromMapT: => FromMap[T],
): FromMap[FieldType[K, V] :: T] = ???
implicit def cnilFromMap: FromMap[CNil] = ???
implicit def coproductFromMap[K <: Symbol, H, T <: Coproduct](implicit
wit: => Witness.Aux[K],
fromMapH: => Lazy[FromMap[H]],
fromMapT: => FromMap[T]
): FromMap[FieldType[K, H] :+: T] = ???
}
trait LowerPriorityFromMapInstances {
implicit def optFromMap[K <: Symbol, V, R <: HList, T <: HList](implicit
witness: => Witness.Aux[K],
gen: => LabelledGeneric.Aux[V, R],
fromMapH: => Lazy[FromMap[R]],
fromMapT: => FromMap[T]
): FromMap[FieldType[K, Option[V]] :: T] = ???
implicit def listFromMap[K <: Symbol, V, R <: HList, T <: HList](implicit
witness: => Witness.Aux[K],
gen: => LabelledGeneric.Aux[V, R],
fromMapH: => Lazy[FromMap[R]],
fromMapT: => FromMap[T]
): FromMap[FieldType[K, List[V]] :: T] = ???
//Other instances as required
implicit def hConsFromMap1[K <: Symbol, V, R <: HList, T <: HList](implicit
wit: => Witness.Aux[K],
gen: => LabelledGeneric.Aux[V, R],
fromMapH: => Lazy[FromMap[R]],
fromMapT: => FromMap[T]
): FromMap[FieldType[K, V] :: T] = ???
}
Compiler is able to find derivations for all cases except for sealed traits. How can I make this work?