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.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