Skip to content

Commit

Permalink
Improve HShow derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin committed Apr 10, 2022
1 parent d41df73 commit 6e11bd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object UnaryDeserializer extends Serializable {
extends Errors(
s"""
|${clz.getName}: could not deserialize the $name input argument:
|should match one of the following types: ${HShow[T].show().trim.init}""".stripMargin
|should match one of the following types: ${HShow[T].show()}""".stripMargin
)
}

Expand Down
14 changes: 10 additions & 4 deletions core/src/main/scala/com/azavea/hiveless/utils/HShow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ object HShow extends LowPriorityHShow {
() => sl.show()

/** Derive HShow for HList. */
implicit val hshowHNil: HShow[HNil] = () => ""
implicit def hshowHCons[H: ClassTag, T <: HList](implicit sh: HShow[H], st: HShow[T]): HShow[H :: T] = () => s"${sh.show()}, ${st.show()}"
implicit val hshowHNil: HShow[HNil] = () => ""
implicit def hshowHCons[H: ClassTag, T <: HList](implicit sh: HShow[H], st: HShow[T]): HShow[H :: T] = () => {
val (h, t) = (sh.show(), st.show())
if (t.isEmpty) h else s"$h, $t"
}

/** Derive HShow for Coproduct. */
implicit val hshowCNil: HShow[CNil] = () => ""
implicit def hshowCCons[H: ClassTag, T <: Coproduct](implicit sh: HShow[H], st: HShow[T]): HShow[H :+: T] = () => s"${sh.show()}, ${st.show()}"
implicit val hshowCNil: HShow[CNil] = () => ""
implicit def hshowCCons[H: ClassTag, T <: Coproduct](implicit sh: HShow[H], st: HShow[T]): HShow[H :+: T] = () => {
val (h, t) = (sh.show(), st.show())
if (t.isEmpty) h else s"$h, $t"
}
}

trait LowPriorityHShow extends Serializable {
Expand Down

0 comments on commit 6e11bd1

Please sign in to comment.