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

Function split

packages/effect/test/Stream/zipping.test.ts:29–42  ·  view source on GitHub ↗
(chunks: Chunk.Chunk<Chunk.Chunk<A>>)

Source from the content-addressed store, hash-verified

27
28export const splitChunks = <A>(chunks: Chunk.Chunk<Chunk.Chunk<A>>): fc.Arbitrary<Chunk.Chunk<Chunk.Chunk<A>>> => {
29 const split = (chunks: Chunk.Chunk<Chunk.Chunk<A>>): fc.Arbitrary<Chunk.Chunk<Chunk.Chunk<A>>> =>
30 fc.integer({ min: 0, max: Math.max(chunks.length - 1, 0) }).chain((i) => {
31 const chunk = Chunk.unsafeGet(chunks, i)
32 return fc.integer({ min: 0, max: Math.max(chunk.length - 1, 0) }).map((j) => {
33 const [left, right] = pipe(chunk, Chunk.splitAt(j))
34 return pipe(
35 chunks,
36 Chunk.take(i),
37 Chunk.appendAll(Chunk.of(left)),
38 Chunk.appendAll(Chunk.of(right)),
39 Chunk.appendAll(pipe(chunks, Chunk.drop(i + 1)))
40 )
41 })
42 })
43 return fc.oneof(fc.constant(chunks), split(chunks).chain((chunks) => splitChunks(chunks)))
44}
45

Callers 1

splitChunksFunction · 0.70

Calls 6

integerMethod · 0.80
unsafeGetMethod · 0.80
mapMethod · 0.65
takeMethod · 0.65
ofMethod · 0.65
pipeFunction · 0.50

Tested by

no test coverage detected