How to compare two instances of the same struct in Cadence?

73 Views Asked by At

I'd like to compare two instances of the same struct to see if their fields have all the same value. I believe that according to the docs the equality operator wont't work on structs.

What would be the right approach here? Writing a custom equals method for the struct?

1

There are 1 best solutions below

0
On

I believe your instincts are right, a custom equals method would be best. Other languages allow for for custom comparators so you can do things like create your own == operator for structs. But that’s not a feature atm in Cadence, so an equals methods like you suggested would work in this instance.