(backing: Backing<A>)
| 163 | } |
| 164 | |
| 165 | const makeChunk = <A>(backing: Backing<A>): Chunk<A> => { |
| 166 | const chunk = Object.create(ChunkProto) |
| 167 | chunk.backing = backing |
| 168 | switch (backing._tag) { |
| 169 | case "IEmpty": { |
| 170 | chunk.length = 0 |
| 171 | chunk.depth = 0 |
| 172 | chunk.left = chunk |
| 173 | chunk.right = chunk |
| 174 | break |
| 175 | } |
| 176 | case "IConcat": { |
| 177 | chunk.length = backing.left.length + backing.right.length |
| 178 | chunk.depth = 1 + Math.max(backing.left.depth, backing.right.depth) |
| 179 | chunk.left = backing.left |
| 180 | chunk.right = backing.right |
| 181 | break |
| 182 | } |
| 183 | case "IArray": { |
| 184 | chunk.length = backing.array.length |
| 185 | chunk.depth = 0 |
| 186 | chunk.left = _empty |
| 187 | chunk.right = _empty |
| 188 | break |
| 189 | } |
| 190 | case "ISingleton": { |
| 191 | chunk.length = 1 |
| 192 | chunk.depth = 0 |
| 193 | chunk.left = _empty |
| 194 | chunk.right = _empty |
| 195 | break |
| 196 | } |
| 197 | case "ISlice": { |
| 198 | chunk.length = backing.length |
| 199 | chunk.depth = backing.chunk.depth + 1 |
| 200 | chunk.left = _empty |
| 201 | chunk.right = _empty |
| 202 | break |
| 203 | } |
| 204 | } |
| 205 | return chunk |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Checks if `u` is a `Chunk<unknown>` |
no test coverage detected