Created
April 12, 2021 16:49
-
-
Save kubukoz/acdd21b379a6a4fa70ffe73fd76232f5 to your computer and use it in GitHub Desktop.
Play JSON format syntax for HLists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shapeless.:: | |
object Extensions extends LowPriorityExtensions { | |
implicit class NotHListOWritesConcat[A](right: OWrites[A])(implicit notHList: shapeless.Refute[A <:< HList]) { | |
//noinspection ScalaStyle | |
def ~::[B](head: OWrites[B]): OWrites[B :: A :: HNil] = (head ~ right) (hlist => (hlist.head, hlist.tail.head)) | |
} | |
implicit class NotHListReadsConcat[A](right: Reads[A])(implicit notHList: shapeless.Refute[A <:< HList]) { | |
//noinspection ScalaStyle | |
def ~::[B](head: Reads[B]): Reads[B :: A :: HNil] = (head ~ right) ((b, a) => b :: a :: HNil) | |
} | |
} | |
trait LowPriorityExtensions { | |
implicit class HListOWritesConcat[A <: HList](right: OWrites[A]) { | |
//noinspection ScalaStyle | |
def ~::[B](head: OWrites[B]): OWrites[B :: A] = (head ~ right) (hlist => (hlist.head, hlist.tail)) | |
} | |
implicit class HListReadsConcat[A <: HList](right: Reads[A]) { | |
//noinspection ScalaStyle | |
def ~::[B](head: Reads[B]): Reads[B :: A] = (head ~ right) ((b, a) => b :: a) | |
} | |
} | |
import Extensions._ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment