Nowadays there is something of a ‘challenge’ going around in performant programming language circles about whether they can implement an easy-to-read Pythagorean triple generator using (infinite) ranges. E.g., see https://atilanevesoncode.wordpress.com/2018/12/31/comparing-pythagorean-triples-in-c-d-and-rust/ . I found this coincidentally amusing because I recently submitted a PR to the Scala documentation site that uses the Pythagorean triple generation as an example to show the power and elegance of for-comprehensions: https://github.com/scala/docs.scala-lang/pull/1235

So naturally I tried converting my example to use an infinite range (concretely, an `Iterator`

):

```
def naturals = Iterator.from(1)
def pythagoreanTriples = for {
a <- naturals
b <- naturals if b > a
c <- naturals if a * a + b * b == c * c
} yield (a, b, c)
pythagoreanTriples take 2 foreach println
```

However, this generator seems to get stuck indefinitely. I tried to rewrite it with slightly more precise functions:

```
def naturals = Iterator.from(1)
def pythagoreanTriples = naturals.flatMap { a =>
naturals.dropWhile(a.>=).flatMap { b =>
naturals.collect {
case c if c * c == a * a + b * b => (a, b, c)
}
}
}
pythagoreanTriples take 2 foreach println
```

However, this generator suffers the same problem–stuck indefinitely.

Can anyone shed light on why the iterators are seemingly not iterating?