zio-schema icon indicating copy to clipboard operation
zio-schema copied to clipboard

Schema deterministic hashcode for DynamicValue

Open carlos-verdes opened this issue 5 months ago • 0 comments

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.

carlos-verdes avatar Jan 30 '24 18:01 carlos-verdes