spice.ItemContainer.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spice-core_sjs1_3 Show documentation
Show all versions of spice-core_sjs1_3 Show documentation
Core functionality leveraged and shared by most other sub-projects of Spice.
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
}