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 } }