I want to create a combination of some values, as in the code below:
object ContinueGenerate { val foods = List("A", "B", "C") val places = List("P1", "P2", "P3") val communities = List("C1", "C2", "C3", "C4") case class Combination(food: String, place: String, community: String) def allCombinations() = { for { food <- foods; place <- places; community <- communities } yield Combination(food, place, community) } def main(args: Array[String]) { allCombinations foreach println } }
However, the problem with this approach is that all data is generated immediately. This is a big problem when the size of foods , places and communities becomes very large. There may also be other parameters besides these three.
Therefore, I want to be able to generate combinations in a continuation style, so that a combination is only created when it is requested.
What would be the idiomatic way for Scala to do this?
scala combinations
tuxdna
source share