From 2b76ad0aa93bda418e6838b5dfe647824b7a9470 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 20 Feb 2023 11:55:14 +0600 Subject: [PATCH] improvements in selectByIds of CommonExposedRepo --- CHANGELOG.md | 4 ++++ .../micro_utils/repos/exposed/CommonExposedRepo.kt | 14 ++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e4ab5259c0..19dc0e3b0e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.16.12 +* `Repos`: + * `Exposed`: + * `CommonExposedRepo.selectByIds` uses `foldRight` by default instead of raw foreach + ## 0.16.11 * `LanguageCodes`: diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/CommonExposedRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/CommonExposedRepo.kt index 8e12921bece..febc8648ddf 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/CommonExposedRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/CommonExposedRepo.kt @@ -7,15 +7,9 @@ interface CommonExposedRepo : ExposedRepo { val ResultRow.asId: IdType val selectById: ISqlExpressionBuilder.(IdType) -> Op val selectByIds: ISqlExpressionBuilder.(List) -> Op - get() = { list -> - if (list.isEmpty()) { - Op.FALSE - } else { - var op = selectById(list.first()) - (1 until list.size).forEach { - op = op.or(selectById(list[it])) - } - op - } + get() = { + it.foldRight?>(null) { id, acc -> + acc ?.or(selectById(id)) ?: selectById(id) + } ?: Op.FALSE } }