Skip to content

Instantly share code, notes, and snippets.

@noel-yap
Last active December 6, 2016 17:14
Show Gist options
  • Select an option

  • Save noel-yap/7f60a3e57f57e6b8ad1a1d8d25d553f2 to your computer and use it in GitHub Desktop.

Select an option

Save noel-yap/7f60a3e57f57e6b8ad1a1d8d25d553f2 to your computer and use it in GitHub Desktop.
#!/bin/bash
exec /opt/scala-2.10/bin/scala -feature "$0" "$@"
!#
class CartesianProduct(product: Traversable[Traversable[_ <: Any]]) {
override def toString(): String = {
product.toString
}
def *(rhs: Traversable[_ <: Any]): CartesianProduct = {
val p = product.flatMap { lhs =>
rhs.map { r =>
lhs.toList :+ r
}
}
new CartesianProduct(p)
}
}
object CartesianProduct {
def apply(traversable: Traversable[_ <: Any]): CartesianProduct = {
new CartesianProduct(
traversable.map { t =>
Traversable(t)
}
)
}
}
val aoeu = CartesianProduct(Set(0, 1))
val snth = Set(2, 3)
val htns = Set(4, 5)
println(aoeu * snth * htns)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment