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

org.hammerlab.show.product.scala Maven / Gradle / Ivy

There is a newer version: 5.2.1
Show newest version
package org.hammerlab.show

import cats.Show
import hammerlab.show._
import shapeless._

trait product {
  implicit val showHNil: Show[HNil] = show { _ ⇒ "" }
  implicit def showHList[H, T <: HList](implicit
                                        head: Show[H],
                                        tail: Show[T]): Show[H :: T] =
    show[H :: T] {
      case h :: HNil ⇒
        h.show
      case h :: t ⇒
        show"$h,$t"
    }

  implicit def showAsHList[T, G <: HList](implicit
                                          generic: Generic.Aux[T, G],
                                          showGeneric: Show[G]
                                         ): Show[T] =
    show {
      t ⇒
        val name =
          t.getClass.getSimpleName match {
            case "" ⇒ "anon"
            case name ⇒ name
          }

        generic.to(t) match {
          case _: HNil ⇒ name.show
          case hl ⇒ show"$name($hl)"
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy