import shapeless.tag | |
import shapeless.tag.@@ | |
trait UserIdTag | |
trait DeviceUuidTag | |
trait CarSerialIdTag | |
type UserId = Long @@ UserIdTag | |
type DeviceUuid = Long @@ DeviceUuidTag | |
type CarSerialId = Long @@ CarSerialIdTag | |
def getHashCodeTagged(userId: UserId, deviceUuid: DeviceUuid, carSerialId: CarSerialId): String = { | |
val userIdPlus: Long = userId + 1 | |
val deviceUuidPlus: Long = deviceUuid + 2 | |
val carSerialIdPlus: Long = carSerialId + 3 | |
s"$userIdPlus-$deviceUuidPlus-$carSerialIdPlus" | |
} | |
val taggedUserId: UserId = tag[UserIdTag][Long](userId) | |
val taggedDeviceUuid: DeviceUuid = tag[DeviceUuidTag][Long](deviceUuid) | |
val taggedCarSerialId: CarSerialId = tag[CarSerialIdTag][Long](carSerialId) | |
getHashCodeTagged(taggedUserId, taggedDeviceUuid, taggedCarSerialId) // Right Answer = res2: String = 13-1236-12348 | |
getHashCodeTagged(taggedDeviceUuid, taggedCarSerialId, taggedUserId) // Not Even Compiled |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment