From f6e819be62394bb813229c90f524dd8e1a63d0b2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 19 Mar 2022 12:49:14 +0600 Subject: [PATCH] simpleFilter to list wrapper --- CHANGELOG.md | 4 ++++ .../behaviour_builder/utils/SimpleFilter.kt | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d98edc2f55..f4fc57e948 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ * `Ktor`: `1.6.7` -> `1.6.8` * `BehaviourBuilder`: * Fixes in `onMediaGroup` and dependent functions + * Add several new extensions for `SimpleFilter`: + * `SimpleFilter#listAll` + * `SimpleFilter#listAny` + * `SimpleFilter#listNone` ## 0.38.7 diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter.kt index 6383a8cbfc..45cdf3b004 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter.kt @@ -4,6 +4,27 @@ 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] */