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

commonMain.ru.casperix.signals.collection.ObservableCollection.kt Maven / Gradle / Ivy

The newest version!
package ru.casperix.signals.collection

import ru.casperix.signals.concrete.Slot
import ru.casperix.signals.concrete.Future


interface ObservableCollection : Collection {
	fun addFuture(): Future
	fun removeFuture(): Future

	fun then(addListener: (Item) -> Unit, removeListener: (Item) -> Unit): Pair {
		return Pair(
				addFuture().then(addListener),
				removeFuture().then(removeListener)
		)
	}

	fun cancel(forAdd: Slot?, forRemove: Slot?) {
		forAdd?.let { addFuture().cancel(it) }
		forRemove?.let { removeFuture().cancel(it) }
	}

	fun thenAdd(listener: (Item) -> Unit): Slot? {
		return addFuture().then(listener)
	}

	fun thenRemove(listener: (Item) -> Unit): Slot? {
		return removeFuture().then(listener)
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy