| 689 | * @since 4.0.0 |
| 690 | */ |
| 691 | export function Struct<R extends Record<string, Equivalence<any>>>( |
| 692 | fields: R |
| 693 | ): Equivalence<{ readonly [K in keyof R]: [R[K]] extends [Equivalence<infer A>] ? A : never }> { |
| 694 | const keys: Array<any> = Reflect.ownKeys(fields) |
| 695 | return make((self, that) => { |
| 696 | for (const key of keys) { |
| 697 | if (!fields[key](self[key], that[key])) return false |
| 698 | } |
| 699 | return true |
| 700 | }) |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * Creates an equivalence for objects by comparing all properties using the same equivalence. |