Suppose I have a simple function that builds an iterator of all the lists of two positive integers (x,y) that are <1000 and have x <= y
def twoIntsIterator(): Iterator[List[Int]] = {
for {
x <- Iterator.range(1, 1000)
y <- Iterator.range(x, 1000)
} yield List(x, y)
}
How would you implement a function intsListIterator(n: Int, limit: Int)
that geneneralizes the list creation to lists of variable length? Such a function would produce the same output of the one above for n=2 and limit=1000. If called with n=3 and limit=4 it would return an iterator that produces the following:
List(1,1,1)
List(1,1,2)
List(1,1,3)
List(1,2,2)
List(1,2,3)
List(1,3,3)
List(2,2,2)
List(2,2,3)
List(2,3,3)
List(3,3,3)
N.B.: I used iterators but they could have been views, the point is the variable list length