Tail-recursive bounded stream of pairs of integers (Scala)?
问题 I'm very new to Scala, so forgive my ignorance! I'm trying to iterate of pairs of integers that are bounded by a maximum. For example, if the maximum is 5, then the iteration should return: (0, 0), (0, 1), ..., (0, 5), (1, 0), ..., (5, 5) I've chosen to try and tail-recursively return this as a Stream: @tailrec def _pairs(i: Int, j: Int, maximum: Int): Stream[(Int, Int)] = { if (i == maximum && j == maximum) Stream.empty else if (j == maximum) (i, j) #:: _pairs(i + 1, 0, maximum) else (i, j)