(backing: Backing<A>)
| 215 | } |
| 216 | |
| 217 | const makeChunk = <A>(backing: Backing<A>): Chunk<A> => { |
| 218 | const chunk = Object.create(ChunkProto) |
| 219 | chunk.backing = backing |
| 220 | switch (backing._tag) { |
| 221 | case "IEmpty": { |
| 222 | chunk.length = 0 |
| 223 | chunk.depth = 0 |
| 224 | chunk.left = chunk |
| 225 | chunk.right = chunk |
| 226 | break |
| 227 | } |
| 228 | case "IConcat": { |
| 229 | chunk.length = backing.left.length + backing.right.length |
| 230 | chunk.depth = 1 + Math.max(backing.left.depth, backing.right.depth) |
| 231 | chunk.left = backing.left |
| 232 | chunk.right = backing.right |
| 233 | break |
| 234 | } |
| 235 | case "IArray": { |
| 236 | chunk.length = backing.array.length |
| 237 | chunk.depth = 0 |
| 238 | chunk.left = _empty |
| 239 | chunk.right = _empty |
| 240 | break |
| 241 | } |
| 242 | case "ISingleton": { |
| 243 | chunk.length = 1 |
| 244 | chunk.depth = 0 |
| 245 | chunk.left = _empty |
| 246 | chunk.right = _empty |
| 247 | break |
| 248 | } |
| 249 | case "ISlice": { |
| 250 | chunk.length = backing.length |
| 251 | chunk.depth = backing.chunk.depth + 1 |
| 252 | chunk.left = _empty |
| 253 | chunk.right = _empty |
| 254 | break |
| 255 | } |
| 256 | } |
| 257 | return chunk |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Checks whether `u` is a `Chunk<unknown>` |
no outgoing calls
no test coverage detected