io.youi.ItemContainer.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of youi-core_sjs0.6_2.13 Show documentation
Show all versions of youi-core_sjs0.6_2.13 Show documentation
Core functionality leveraged and shared by most other sub-projects of YouI.
The newest version!
package io.youi
import reactify.{Val, Var}
import scala.math.Ordering
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