Created
August 30, 2019 13:27
-
-
Save Vilkina/77dfe5ede299c30cd452d0d0d42fa321 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def zipAllWith[@specialized B, @specialized C](that: Chunk[B])(left: A => C, right: B => C)(both: (A, B) => C): Chunk[C] = { | |
val size = self.length.max(that.length) | |
val minln = self.length.min(that.length) | |
if (size == 0 && minln == 0) Chunk.empty | |
else { | |
var j = 0 | |
val c = both(self(j), that(j)) | |
implicit val C: ClassTag[C] = Chunk.Tags.fromValue(c) | |
val dest = Array.ofDim[C](size) | |
while (j < minln) { | |
dest(j) = c | |
if (j < size) { | |
val b = left(self(j)) | |
dest(j) = b | |
j = j + 1 | |
} else { | |
val dx = right(that(j)) | |
dest(j) = dx | |
j += 1 | |
} | |
} | |
Chunk.Arr(dest) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment