MCPcopy Index your code
hub / github.com/Effect-TS/effect / merge

Function merge

packages/effect/src/internal/stream.ts:7993–8079  ·  view source on GitHub ↗
(
      leftChunk: Chunk.Chunk<readonly [K, A]>,
      rightChunk: Chunk.Chunk<readonly [K, A2]>
    )

Source from the content-addressed store, hash-verified

7991 }
7992 }
7993 const merge = (
7994 leftChunk: Chunk.Chunk<readonly [K, A]>,
7995 rightChunk: Chunk.Chunk<readonly [K, A2]>
7996 ): readonly [
7997 Chunk.Chunk<[K, A3]>,
7998 ZipAllState.ZipAllState<readonly [K, A], readonly [K, A2]>
7999 ] => {
8000 const hasNext = <T>(chunk: Chunk.Chunk<T>, index: number) => index < chunk.length - 1
8001 const builder: Array<[K, A3]> = []
8002 let state:
8003 | ZipAllState.ZipAllState<
8004 readonly [K, A],
8005 readonly [K, A2]
8006 >
8007 | undefined = undefined
8008 let leftIndex = 0
8009 let rightIndex = 0
8010 let leftTuple = pipe(leftChunk, Chunk.unsafeGet(leftIndex))
8011 let rightTuple = pipe(rightChunk, Chunk.unsafeGet(rightIndex))
8012 let k1 = leftTuple[0]
8013 let a = leftTuple[1]
8014 let k2 = rightTuple[0]
8015 let a2 = rightTuple[1]
8016 let loop = true
8017 while (loop) {
8018 const compare = options.order(k1, k2)
8019 if (compare === 0) {
8020 builder.push([k1, options.onBoth(a, a2)])
8021 if (hasNext(leftChunk, leftIndex) && hasNext(rightChunk, rightIndex)) {
8022 leftIndex = leftIndex + 1
8023 rightIndex = rightIndex + 1
8024 leftTuple = pipe(leftChunk, Chunk.unsafeGet(leftIndex))
8025 rightTuple = pipe(rightChunk, Chunk.unsafeGet(rightIndex))
8026 k1 = leftTuple[0]
8027 a = leftTuple[1]
8028 k2 = rightTuple[0]
8029 a2 = rightTuple[1]
8030 } else if (hasNext(leftChunk, leftIndex)) {
8031 state = ZipAllState.PullRight(pipe(leftChunk, Chunk.drop(leftIndex + 1)))
8032 loop = false
8033 } else if (hasNext(rightChunk, rightIndex)) {
8034 state = ZipAllState.PullLeft(pipe(rightChunk, Chunk.drop(rightIndex + 1)))
8035 loop = false
8036 } else {
8037 state = ZipAllState.PullBoth
8038 loop = false
8039 }
8040 } else if (compare < 0) {
8041 builder.push([k1, options.onSelf(a)])
8042 if (hasNext(leftChunk, leftIndex)) {
8043 leftIndex = leftIndex + 1
8044 leftTuple = pipe(leftChunk, Chunk.unsafeGet(leftIndex))
8045 k1 = leftTuple[0]
8046 a = leftTuple[1]
8047 } else {
8048 const rightBuilder: Array<readonly [K, A2]> = []
8049 rightBuilder.push(rightTuple)
8050 while (hasNext(rightChunk, rightIndex)) {

Callers 5

collectAllToMapFunction · 0.70
collectAllToMapNFunction · 0.70
stream.tsFile · 0.70
pullFunction · 0.70
passthroughFunction · 0.70

Calls 3

hasNextFunction · 0.85
unsafeGetMethod · 0.80
pipeFunction · 0.70

Tested by

no test coverage detected