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

spice.ItemContainer.scala Maven / Gradle / Ivy

There is a newer version: 0.5.14
Show newest version
package spice

import reactify.{Val, Var}

class ItemContainer[T](implicit ord: Ordering[T]) extends Iterable[T] {
  private val list = Var[List[T]](Nil)
  val items: Val[List[T]] = list

  def +=(item: T): Unit = synchronized {
    list @= (item :: list()).sorted
  }
  def -=(item: T): Unit = synchronized {
    list @= list().filterNot(_ == item)
  }
  def apply(): List[T] = items()

  override def iterator: Iterator[T] = items().iterator
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy