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

commonMain.ru.casperix.signals.concrete.FutureExtension.kt Maven / Gradle / Ivy

There is a newer version: 1.8.2
Show newest version
package ru.casperix.signals.concrete

import ru.casperix.misc.Either
import ru.casperix.misc.fold
import ru.casperix.signals.api.CustomFuture



/**
 * 	Искомый сигнал срабатывает от любого инициатора
 */
fun  CustomFuture<(Input) -> Unit, Slot>.transform(converter: (Input) -> Output): CustomFuture<(Output) -> Unit, Slot> {
	val signal = Signal()
	then {
		signal.set(converter(it))
	}
	return signal
}

fun  EitherFuture.map(acceptConverter: (Accept) -> Either, rejectConverter: (Reject) -> NextReject): EitherFuture {
	return mapAccept(acceptConverter).mapReject(rejectConverter)
}

fun  EitherFuture.mapAccept(acceptConverter: (Accept) -> Either): EitherFuture {
	val nextSignal = EitherSignal()
	then({
		acceptConverter(it).fold({
			nextSignal.reject(it)
		}, {
			nextSignal.accept(it)
		})
	}, {
		nextSignal.reject(it)
	})
	return nextSignal
}

fun  EitherFuture.mapReject(rejectConverter: (Reject) -> NextReject): EitherFuture {
	val nextSignal = EitherSignal()
	then({
		nextSignal.accept(it)
	}, {
		nextSignal.reject(rejectConverter(it))
	})
	return nextSignal
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy