zio-schema
zio-schema copied to clipboard
Schema deterministic hashcode for DynamicValue
I'm creating a ddd store for Entity and ValueObject.
ValueObject will use it's hashcode as key in the store (and I'll manage collisions storing a list instead of a single value object)
My current approach use something like this:
trait ValueObject[R]:
def schema: Schema[R]
extension (valueObject: R)
def isSameValueObjectAs(other: R): Boolean =
schema.diff(valueObject, other).isIdentical
def valueHashCode: Long =
schema.toDynamic(valueObject).hashCode
This way I can do something like store.getValueObject[T: ValueObject](valueObject: T).filter(found => found.isSameValueObjectAs(valueObject).runHead
However in my tests I observe the hashCode generated using DynamicValue changes, making my code fail.