<commit_before>package rescala

import rescala.turns.{Turn, Engine}
import rescala.graph.{EvaluationResult, Pulse}


/**
 * An implementation of an imperative event
 */
final class Evt[T]() extends Event[T] {

  /** Trigger the event */
  def apply(v: T)(implicit fac: Engine): Unit = fac.startNew { turn =>
    turn.admit(this) {
      pulses.set(Pulse.change(v))(turn)
      true
    }
  }

  override protected[rescala] def reevaluate()(implicit turn: Turn): EvaluationResult =
    EvaluationResult.Static(changed = true)
}

object Evt {
  def apply[T]() = new Evt[T]()
}



/** A root Reactive value without dependencies which can be set */
final class Var[T](initval: T) extends Signal[T] {
  pulses.current = Pulse.unchanged(initval)

  def update(newValue: T)(implicit fac: Engine): Unit = set(newValue)
  def set(newValue: T)(implicit fac: Engine): Unit = fac.startNew { turn =>
    admit(newValue)(turn)
  }

  def admit(newValue: T)(implicit turn: Turn): Unit =
    turn.admit(this) {
      val p = Pulse.diff(newValue, get)
      if (p.isChange) {
        pulses.set(p)
        true
      }
      else false
    }

  override protected[rescala] def reevaluate()(implicit turn: Turn): EvaluationResult =
    EvaluationResult.Static(changed = true)
}

object Var {
  def apply[T](initval: T) = new Var(initval)
}
<commit_msg>add common source interface<commit_after>package rescala

import rescala.turns.{Turn, Engine}
import rescala.graph.{EvaluationResult, Pulse}

sealed trait Source[T] {
  def admit(value: T)(implicit turn: Turn): Unit
}

/**
 * An implementation of an imperative event
 */
final class Evt[T]() extends Event[T] with Source[T] {

  /** Trigger the event */
  def apply(value: T)(implicit fac: Engine): Unit = fac.startNew { admit(value)(_) }

  def admit(value: T)(implicit turn: Turn): Unit =
    turn.admit(this) {
      pulses.set(Pulse.change(value))(turn)
      true
    }

  override protected[rescala] def reevaluate()(implicit turn: Turn): EvaluationResult =
    EvaluationResult.Static(changed = true)
}

object Evt {
  def apply[T]() = new Evt[T]()
}



/** A root Reactive value without dependencies which can be set */
final class Var[T](initval: T) extends Signal[T] with Source[T] {
  pulses.current = Pulse.unchanged(initval)

  def update(value: T)(implicit fac: Engine): Unit = set(value)
  def set(value: T)(implicit fac: Engine): Unit = fac.startNew { admit(value)(_) }

  def admit(value: T)(implicit turn: Turn): Unit =
    turn.admit(this) {
      val p = Pulse.diff(value, get)
      if (p.isChange) {
        pulses.set(p)
        true
      }
      else false
    }

  override protected[rescala] def reevaluate()(implicit turn: Turn): EvaluationResult =
    EvaluationResult.Static(changed = true)
}

object Var {
  def apply[T](initval: T) = new Var(initval)
}

{'fraction_non_alphanumeric': 0.13373536715147216, 'fraction_numerical': 0.0, 'mean_word_length': 3.607843137254902, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7465546', 'n_tokens_mistral': 971, 'n_tokens_neox': 931, 'n_words': 251}