| 640 | * @since 4.0.0 |
| 641 | */ |
| 642 | export function Struct<R extends Record<PropertyKey, Order<any>>>( |
| 643 | fields: R |
| 644 | ): Order<{ readonly [K in keyof R]: [R[K]] extends [Order<infer A>] ? A : never }> { |
| 645 | const keys = InternalRecord.ownEnumerableKeys(fields) as Array<keyof R> |
| 646 | return make((self, that) => { |
| 647 | for (const key of keys) { |
| 648 | const o = fields[key](self[key], that[key]) |
| 649 | if (o !== 0) { |
| 650 | return o |
| 651 | } |
| 652 | } |
| 653 | return 0 |
| 654 | }) |
| 655 | } |
| 656 | |
| 657 | /** |
| 658 | * Checks whether one value is strictly less than another according to the given order. |