Skip to content

Instantly share code, notes, and snippets.

@SethTisue
Created June 17, 2012 00:34
Show Gist options
  • Save SethTisue/2942990 to your computer and use it in GitHub Desktop.
Save SethTisue/2942990 to your computer and use it in GitHub Desktop.
add zipWith to Iterable
// add zipWith to Iterable; thank you stackoverflow.com/q/3895813
implicit class RichIterable[A, CC[X] <: Iterable[X]](xs: CC[A]) {
type Builder[C] = collection.generic.CanBuildFrom[Nothing, C, CC[C]]
def zipWith[B, C](ys: Iterable[B])(f: (A, B) => C)(implicit cbf: Builder[C]): CC[C] =
xs.zip(ys).map(f.tupled)(collection.breakOut)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment