fuookami.ospf.kotlin.utils.functional.Predicate.kt Maven / Gradle / Ivy
package fuookami.ospf.kotlin.utils.functional
import fuookami.ospf.kotlin.utils.operator.*
typealias Predicate = (T) -> Boolean
typealias TryPredicate = (T) -> Ret
typealias SuspendPredicate = suspend (T) -> Boolean
typealias SuspendTryPredicate = suspend (T) -> Ret
typealias IndexedPredicate = (Int, T) -> Boolean
typealias TryIndexedPredicate = (Int, T) -> Ret
typealias SuspendIndexedPredicate = suspend (Int, T) -> Boolean
typealias SuspendTryIndexedPredicate = suspend (Int, T) -> Ret
typealias Extractor = (T) -> R
typealias TryExtractor = (T) -> Ret
typealias SuspendExtractor = suspend (T) -> R
typealias SuspendTryExtractor = suspend (T) -> Ret
typealias IndexedExtractor = (Int, T) -> R
typealias TryIndexedExtractor = (Int, T) -> Ret
typealias SuspendIndexedExtractor = suspend (Int, T) -> R
typealias SuspendTryIndexedExtractor = suspend (Int, T) -> Ret
typealias Mapper = (T) -> R
typealias TryMapper = (T) -> Ret
typealias KComparator = kotlin.Comparator
typealias Comparator = (T, T) -> Boolean
typealias PartialComparator = (T, T) -> Boolean?
typealias TryComparator = (T, T) -> Ret
typealias ThreeWayComparator = (T, T) -> Order
typealias PartialThreeWayComparator = (T, T) -> Order?
typealias TryThreeWayComparator = (T, T) -> Ret
typealias Generator = () -> R?
inline infix fun Predicate.and(crossinline rhs: Predicate) = { it: U -> this(it as T) and rhs(it) }
inline infix fun Predicate.or(crossinline rhs: Predicate) = { it: U -> this(it) or rhs(it) }
inline infix fun Predicate.xor(crossinline rhs: Predicate) = { it: U -> this(it) xor rhs(it) }
operator fun Predicate.not(): Predicate = { it: T -> !this(it) }
operator fun ThreeWayComparator.not(): ThreeWayComparator = { lhs, rhs: T -> orderOf(-this(lhs, rhs).value) }
fun kotlin.Comparator.threeWay(): ThreeWayComparator {
return { lhs, rhs -> orderOf(this.compare(lhs, rhs)) }
}