Skip to content

Instantly share code, notes, and snippets.

@daithiocrualaoich
Created August 2, 2011 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daithiocrualaoich/1119974 to your computer and use it in GitHub Desktop.
Save daithiocrualaoich/1119974 to your computer and use it in GitHub Desktop.
Pimping scala.collections
implicit def iterable2Cross[T, C[T] <: Iterable[T]](tees: C[T]) = new {
import collection.generic.CanBuildFrom
def cross[S](esses: Iterable[S])(implicit cbf: CanBuildFrom[C[(T,S)],(T,S),C[(T,S)]]): C[(T,S)] = {
val builder = cbf()
val rst = for (t <- tees; s <- esses) yield (t, s)
rst foreach { builder += }
builder.result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment