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

commonMain.ru.casperix.signals.Extensions.kt Maven / Gradle / Ivy

package ru.casperix.signals

import ru.casperix.signals.collection.ObservableCollection
import ru.casperix.signals.collection.ObservableMap
import ru.casperix.misc.Disposable
import ru.casperix.signals.concrete.*


fun  Signal.map(convert:(Source)->Target): Signal {
	val other = Signal()
	then {
		other.set(convert(it))
	}
	return other
}

fun  ObservableMap.then(holder: MutableCollection, forAdd: (Map.Entry) -> Unit, forRemove: (Map.Entry) -> Unit) {
	thenAdd(forAdd)?.let { holder.add(it) }
	thenRemove(forRemove)?.let { holder.add(it) }
}


fun  ObservableMap.thenAdd(holder: MutableCollection, listener: (Map.Entry) -> Unit) {
	 addFuture().then(holder, listener)
}

fun  ObservableMap.thenRemove(holder: MutableCollection, listener: (Map.Entry) -> Unit) {
	removeFuture().then(holder, listener)
}

fun  ObservableMap.thenAddKey(holder: MutableCollection, listener: (Key) -> Unit) {
	addFuture().then(holder) { listener(it.key) }
}

fun  ObservableMap.thenRemoveKey(holder: MutableCollection, listener: (Key) -> Unit) {
	removeFuture().then(holder) { listener(it.key) }
}

fun  ObservableMap.thenAddValue(holder: MutableCollection, listener: (Value) -> Unit) {
	addFuture().then(holder) { listener(it.value) }
}

fun  ObservableMap.thenRemoveValue(holder: MutableCollection, listener: (Value) -> Unit) {
	removeFuture().then(holder) { listener(it.value) }
}

fun  ObservableCollection.then(holder: MutableCollection, forAdd: (T) -> Unit, forRemove: (T) -> Unit) {
	thenAdd(forAdd)?.let { holder.add(it) }
	thenRemove(forRemove)?.let { holder.add(it) }
}

fun  ObservableCollection.thenAdd(holder: MutableCollection, forAdd: (T) -> Unit) {
	thenAdd(forAdd)?.let { holder.add(it) }
}

fun  ObservableCollection.thenRemove(holder: MutableCollection, forRemove: (T) -> Unit) {
	thenRemove(forRemove)?.let { holder.add(it) }
}

fun  Future.then(holder: MutableCollection, listener: (Event) -> Unit) {
	holder.add(then(listener))
}

fun  UpdateFuture.then(holder: MutableCollection, listener: (Event, Event) -> Unit) {
	holder.add(then(listener))
}

fun EmptyFuture.then(holder: MutableCollection, listener: () -> Unit) {
	holder.add(then(listener))
}

fun EmptyEitherFuture.then(holder: MutableCollection, onAccept: () -> Unit, onReject: () -> Unit) {
	acceptFuture.then(holder, onAccept)
	rejectFuture.then(holder, onReject)
}

fun EmptyEitherFuture.thenAccept(holder: MutableCollection, onAccept: () -> Unit) {
	acceptFuture.then(holder, onAccept)
}

fun EmptyEitherFuture.thenReject(holder: MutableCollection, onReject: () -> Unit) {
	rejectFuture.then(holder, onReject)
}

fun  EitherFuture.then(holder: MutableCollection, onAccept: (Accept) -> Unit, onReject: (Reject) -> Unit) {
	acceptFuture.then(holder, onAccept)
	rejectFuture.then(holder, onReject)
}

fun  EitherFuture.thenAccept(holder: MutableCollection, onAccept: (Accept) -> Unit) {
	acceptFuture.then(holder, onAccept)
}

fun  EitherFuture.thenReject(holder: MutableCollection, onReject: (Reject) -> Unit) {
	rejectFuture.then(holder, onReject)
}

fun BooleanSwitcher.switch() {
	value = !value
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy