improvements in selectByIds of CommonExposedRepo

This commit is contained in:
InsanusMokrassar 2023-02-20 11:55:14 +06:00
parent e4b619e050
commit 2b76ad0aa9
2 changed files with 8 additions and 10 deletions

View File

@ -2,6 +2,10 @@
## 0.16.12 ## 0.16.12
* `Repos`:
* `Exposed`:
* `CommonExposedRepo.selectByIds` uses `foldRight` by default instead of raw foreach
## 0.16.11 ## 0.16.11
* `LanguageCodes`: * `LanguageCodes`:

View File

@ -7,15 +7,9 @@ interface CommonExposedRepo<IdType, ObjectType> : ExposedRepo {
val ResultRow.asId: IdType val ResultRow.asId: IdType
val selectById: ISqlExpressionBuilder.(IdType) -> Op<Boolean> val selectById: ISqlExpressionBuilder.(IdType) -> Op<Boolean>
val selectByIds: ISqlExpressionBuilder.(List<IdType>) -> Op<Boolean> val selectByIds: ISqlExpressionBuilder.(List<IdType>) -> Op<Boolean>
get() = { list -> get() = {
if (list.isEmpty()) { it.foldRight<IdType, Op<Boolean>?>(null) { id, acc ->
Op.FALSE acc ?.or(selectById(id)) ?: selectById(id)
} else { } ?: Op.FALSE
var op = selectById(list.first())
(1 until list.size).forEach {
op = op.or(selectById(list[it]))
}
op
}
} }
} }