sclass BestOfN<A> implements Steppable {
  IF1<A, Double> scoreFunction;
  IF0<A> produce;
  long nMax = 1000;
  double stopScore = infinity();
  
  long attempt;
  new Best<A> best;
  
  *(IF1<A, Double> *scoreFunction, IF0<A> *produce, int *nMax) {}
  *(IF1<A, Double> *scoreFunction, int *nMax) {}
  
  public bool step() {
    if (attempt >= nMax || best.score() >= stopScore) false;
    ++attempt;
    A a = produce!;
    double score = scoreFunction.get(a);
    best.put(a, score);
    true;
  }
  
  run { stepAll(this); }
  
  Scored<A> get() {
    run();
    ret best.scored();
  }
  
  double score() {
    ret best.score();
  }
  
  long attempts() { ret attempt; }
}