There is a good question which says that we should Stream/View or Iterate our collections to make them on-demand. It is clear. I just do not understand what should I apply the .view
or .iterate
to in the following demo
val l1 = List("10", "00", "0")
def gen(depth: Int): Iterable[String] = if (depth == 1) l1 else {
for (sub <- gen(depth-1); item <- List(depth + sub, sub+sub, sub)) yield item
}
Should I apply them to gen(depth-1)
or to List(depth+..)
?
By the way, should I inline l1
in the (depth == 1) l1 else
? It is not used anywhere else. I just afraid that it would create a new list for every leaf.