All Downloads are FREE. Search and download functionalities are using the official Maven repository.

orcus.bigtable.codec.DerivedRowDecoder.scala Maven / Gradle / Ivy

The newest version!
package orcus.bigtable.codec

import shapeless.*
import shapeless.labelled.*

trait DerivedRowDecoder[A] extends RowDecoder[A]

object DerivedRowDecoder extends DerivedRowDecoder1

private[codec] trait DerivedRowDecoder1 {

  implicit val decodeHNil: DerivedRowDecoder[HNil] = _ => Right(HNil)

  implicit def decodeLabelledHCons[K <: Symbol, H, T <: HList](implicit
    K: Witness.Aux[K],
    H: FamilyDecoder[H],
    T: Lazy[DerivedRowDecoder[T]]
  ): DerivedRowDecoder[FieldType[K, H] :: T] =
    row =>
      T.value(row) match {
        case Right(t) =>
          H(row.families.getOrElse(K.value.name, null)) match {
            case Right(h) => Right(field[K](h) :: t)
            case Left(e)  => Left(e)
          }
        case Left(e) =>
          Left(e)
      }

  implicit def decodeLabelledGen[H <: HList, A](implicit
    gen: LabelledGeneric.Aux[A, H],
    A: Lazy[DerivedRowDecoder[H]]
  ): DerivedRowDecoder[A] =
    result =>
      A.value(result) match {
        case Right(v) => Right(gen.from(v))
        case Left(e)  => Left(e)
      }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy