Last active
December 6, 2016 17:14
-
-
Save noel-yap/7f60a3e57f57e6b8ad1a1d8d25d553f2 to your computer and use it in GitHub Desktop.
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
| #!/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