Created
August 2, 2011 10:22
-
-
Save daithiocrualaoich/1119974 to your computer and use it in GitHub Desktop.
Pimping scala.collections
This file contains hidden or 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
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