<commit_before>package rescala.propagation

import rescala.graph.ReevaluationResult.{Dynamic, Static}
import rescala.graph.{DepDiff, Reactive}
import rescala.turns.Turn

object Evaluator {

  /** evaluates a single reactive */
  def evaluate(head: Reactive)(implicit turn: Turn): Result = {
    val result = head.reevaluate()
    result match {
      case Static(hasChanged) => Result(head, hasChanged, -42, None, redo = false)
      case Dynamic(hasChanged, diff) =>
        val newLevel = maximumLevel(diff.novel) + 1
        if (head.level.get >= newLevel) {
          Result(head, hasChanged, newLevel, Some(diff), redo = false)
        }
        else {
          Result(head, hasChanged, newLevel, Some(diff), redo = true)
        }
    }
  }

  def maximumLevel(dependencies: Set[Reactive])(implicit turn: Turn): Int = dependencies.foldLeft(-1)((acc, r) => math.max(acc, r.level.get))

  case class Result(head: Reactive, changed: Boolean, level: Int, getDiff: Option[DepDiff], redo: Boolean) {<commit_msg>simplify Evaluator<commit_after>package rescala.propagation

import rescala.graph.ReevaluationResult.{Dynamic, Static}
import rescala.graph.{DepDiff, Reactive}
import rescala.turns.Turn

object Evaluator {

  /** evaluates a single reactive */
  def evaluate(head: Reactive)(implicit turn: Turn): Result = {
    val result = head.reevaluate()
    result match {
      case Static(hasChanged) => Result(head, hasChanged, -42, None, redo = false)
      case Dynamic(hasChanged, diff) =>
        val newLevel = maximumLevel(diff.novel) + 1
        Result(head, hasChanged, newLevel, Some(diff), redo = head.level.get < newLevel)
    }
  }

  def maximumLevel(dependencies: Set[Reactive])(implicit turn: Turn): Int = dependencies.foldLeft(-1)((acc, r) => math.max(acc, r.level.get))

  case class Result(head: Reactive, changed: Boolean, level: Int, getDiff: Option[DepDiff], redo: Boolean) {
{'fraction_non_alphanumeric': 0.12842105263157894, 'fraction_numerical': 0.004210526315789474, 'mean_word_length': 3.899484536082474, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7312579', 'n_tokens_mistral': 616, 'n_tokens_neox': 586, 'n_words': 152}