| 668 | }) |
| 669 | |
| 670 | const getUnchecked = <A>(self: Chunk<A>, i: number): A => { |
| 671 | switch (self.backing._tag) { |
| 672 | case "IEmpty": { |
| 673 | throw new Error(`Index out of bounds: ${i}`) |
| 674 | } |
| 675 | case "ISingleton": { |
| 676 | return self.backing.a |
| 677 | } |
| 678 | case "IArray": { |
| 679 | return self.backing.array[i]! |
| 680 | } |
| 681 | case "IConcat": { |
| 682 | return i < self.left.length |
| 683 | ? getUnchecked(self.left, i) |
| 684 | : getUnchecked(self.right, i - self.left.length) |
| 685 | } |
| 686 | case "ISlice": { |
| 687 | return getUnchecked(self.backing.chunk, i + self.backing.offset) |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | /** |
| 693 | * Appends the specified element to the end of the `Chunk`. |