iterateWhile<U> static method

IList<U> iterateWhile<U>(
  1. U base,
  2. Predicate<U> test,
  3. Op<U> op
)

Apply Op on previous state of base while predicate pass then return all results

Implementation

static IList<U> iterateWhile<U>(U base, Predicate<U> test, Op<U> op) {
  final l = <U>[];
  U acc = base;
  l.add(acc);

  while (test(acc)) {
    acc = op(l.last);
    l.add(acc);
  }

  return l.lock;
}