package dev.inmo.tgbotapi.extensions.behaviour_builder.utils typealias SimpleFilter = suspend (T) -> Boolean inline fun SimpleFilter(noinline block: SimpleFilter) = block /** * @return [SimpleFilter] which will return true in case when all the items in incoming data passed [this] filter */ fun SimpleFilter.listAll() = SimpleFilter> { it.all { this@listAll(it) } } /** * @return [SimpleFilter] which will return true in case when there is any item in incoming data passed [this] filter */ fun SimpleFilter.listAny() = SimpleFilter> { it.any { this@listAny(it) } } /** * @return [SimpleFilter] which will return true in case when there is no any item in incoming data passed [this] filter */ fun SimpleFilter.listNone() = SimpleFilter> { it.none { this@listNone(it) } } /** * Makes an AND (&&) operation between [this] and [other] */ operator fun SimpleFilter?.times(other: SimpleFilter): SimpleFilter = this ?.let { { this(it) && other(it) } } ?: other /** * Makes an OR (||) operation between [this] and [other] */ operator fun SimpleFilter?.plus(other: SimpleFilter): SimpleFilter = this ?.let { { this(it) || other(it) } } ?: other /** * Reverse results of [this] */ operator fun SimpleFilter.not(): SimpleFilter = { !this(it) }