Ich mag wie im Code eine Kombination aus einigen Werten erzeugen unter:Idiomatic Scala Art und Weise der Erzeugung von Kombinationen lazily
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
}
}
jedoch das Problem mit diesem Ansatz ist, dass alle Daten auf einmal erzeugt werden. Dies ist ein großes Problem, wenn die Größe von foods
, places
und communities
sehr groß wird. Es könnte auch andere Parameter als diese drei geben.
Also ich möchte in der Lage sein, Kombinationen in einer Fortsetzung Stil, so dass eine Kombination nur generiert wird, wenn es angefordert wird.
Was wäre eine idiomatische Scala?