All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.sciss.lucre.impl.MappingEventNode.scala Maven / Gradle / Ivy

Go to download

Extension of Scala-STM, adding optional durability layer, and providing API for confluent and reactive event layers

The newest version!
/*
 *  MappingEventNode.scala
 *  (Lucre 4)
 *
 *  Copyright (c) 2009-2024 Hanns Holger Rutz. All rights reserved.
 *
 *  This software is published under the GNU Affero General Public License v3+
 *
 *
 *  For further information, please contact Hanns Holger Rutz at
 *  [email protected]
 */

package de.sciss.lucre
package impl

/** A trait which combined external input events with self generated events. */
trait MappingEventNode[T <: Txn[T], A, B]
  extends Event.Node[T] {

  protected def inputEvent: EventLike[T, B]

  /** Folds a new input event, by combining it with an optional previous output event. */
  protected def foldUpdate(generated: Option[A], input: B)(implicit tx: T): Option[A]

  trait Mapped extends GeneratorEvent[T, A] {
    private[lucre] final def pullUpdate(pull: Pull[T])(implicit tx: T): Option[A] = {
      val gen = if (pull.isOrigin(this)) Some(pull.resolve[A]) else None
      if (pull.contains(inputEvent)) pull(inputEvent) match {
        case Some(e)  => foldUpdate(gen, e)
        case _        => gen
      } else gen
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy