positive property

Iterable<Fraction> positive

Infinite iterable over all positive fractions.

This is the breadth-first traversal of the Calkin–Wilf tree: https://en.m.wikipedia.org/wiki/Calkin%E2%80%93Wilf_tree

Implementation

static Iterable<Fraction> get positive sync* {
  final pending = QueueList.from([Fraction.one]);
  for (;;) {
    final current = pending.removeFirst();
    pending.addLast(Fraction._(current.a, current.a + current.b));
    pending.addLast(Fraction._(current.a + current.b, current.b));
    yield current;
  }
}