Skip to content

Instantly share code, notes, and snippets.

@knightpop
Created September 9, 2017 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knightpop/7b302288b5ec2a93ef6f8a9e2b550ede to your computer and use it in GitHub Desktop.
Save knightpop/7b302288b5ec2a93ef6f8a9e2b550ede to your computer and use it in GitHub Desktop.
import shapeless.{Coproduct, CNil, :+:, Inl, Inr}
type Id = UserId :+: DeviceUuid :+: CarSerialId :+: CNil
def getId(id: Id): Long = id match {
case Inl(userId) => userId + 1
case Inr(Inl(deviceUuid)) => deviceUuid + 2
case Inr(Inr(Inl(carSerialId))) => carSerialId + 3
case Inr(Inr(Inr(cNil))) => 0
}
getId(Coproduct[Id](taggedUserId))
getId(Coproduct[Id](taggedDeviceUuid))
getId(Coproduct[Id](taggedCarSerialId))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment