Skip to content

Instantly share code, notes, and snippets.

@Vilkina
Created August 30, 2019 13:27
Show Gist options
  • Save Vilkina/77dfe5ede299c30cd452d0d0d42fa321 to your computer and use it in GitHub Desktop.
Save Vilkina/77dfe5ede299c30cd452d0d0d42fa321 to your computer and use it in GitHub Desktop.
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