| 616 | * @since 4.0.0 |
| 617 | */ |
| 618 | export function Struct<const R extends { readonly [x: string]: Order<any> }>( |
| 619 | fields: R |
| 620 | ): Order<{ [K in keyof R]: [R[K]] extends [Order<infer A>] ? A : never }> { |
| 621 | const keys = Object.keys(fields) |
| 622 | return make((self, that) => { |
| 623 | for (const key of keys) { |
| 624 | const o = fields[key](self[key], that[key]) |
| 625 | if (o !== 0) { |
| 626 | return o |
| 627 | } |
| 628 | } |
| 629 | return 0 |
| 630 | }) |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Checks whether one value is strictly less than another according to the given order. |