2021-08-03 05:46:23 +00:00
|
|
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils
|
|
|
|
|
|
|
|
typealias SimpleFilter<T> = suspend (T) -> Boolean
|
2021-09-13 17:30:01 +00:00
|
|
|
|
|
|
|
inline fun <T> SimpleFilter(noinline block: SimpleFilter<T>) = block
|
|
|
|
|
|
|
|
/**
|
2021-09-21 15:36:52 +00:00
|
|
|
* Makes an AND (&&) operation between [this] and [other]
|
2021-09-13 17:30:01 +00:00
|
|
|
*/
|
|
|
|
operator fun <T> SimpleFilter<T>.times(other: SimpleFilter<T>): SimpleFilter<T> = {
|
|
|
|
this(it) && other(it)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-09-21 15:36:52 +00:00
|
|
|
* Makes an OR (||) operation between [this] and [other]
|
2021-09-13 17:30:01 +00:00
|
|
|
*/
|
|
|
|
operator fun <T> SimpleFilter<T>.plus(other: SimpleFilter<T>): SimpleFilter<T> = {
|
|
|
|
this(it) || other(it)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-09-21 15:36:52 +00:00
|
|
|
* Reverse results of [this]
|
2021-09-13 17:30:01 +00:00
|
|
|
*/
|
|
|
|
operator fun <T> SimpleFilter<T>.not(): SimpleFilter<T> = {
|
|
|
|
!this(it)
|
|
|
|
}
|