MCPcopy
hub / github.com/Effect-TS/effect / makeChunk

Function makeChunk

packages/effect/src/Chunk.ts:165–206  ·  view source on GitHub ↗
(backing: Backing<A>)

Source from the content-addressed store, hash-verified

163}
164
165const 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>`

Callers 4

Chunk.tsFile · 0.85
ofFunction · 0.85
reverseChunkFunction · 0.85
unsafeFromArrayFunction · 0.85

Calls 1

createMethod · 0.80

Tested by

no test coverage detected