!7

static JTextField tf;
static JTextArea textArea;
static ConcurrentEvaluator currentEval;

p-substance {
  showFrame(northAndCenter(tf = jtextfield(), textArea = jtextarea()));
  onEnter(tf, f update);
}

svoid update {
  if (currentEval != null) currentEval.cancelAndWait();
  final new ConcurrentEvaluator eval;
  currentEval = eval;
  eval.addAll(evaluators(getText(tf)));
  eval.onNewResult = r { updateResults(eval) };
  eval.start();
}

svoid updateResults(ConcurrentEvaluator eval) {
  setText(textArea, lines(allToString(notNullOnly(eval.results()))));
}

static int coresToUse() { ret max(1, numberOfCores()-1); }

static L evaluators(fS s) {
  ret ll(
    func() { "trimmed: " + trim(s) },
    func() { "without punctuation: " + dropPunctuation(s) },
  );
}