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
* `Repos`:
* `Exposed`:
* `CommonExposedRepo.selectByIds` uses `foldRight` by default instead of raw foreach
## 0.16.11
* `LanguageCodes`:

View File

@ -7,15 +7,9 @@ interface CommonExposedRepo<IdType, ObjectType> : ExposedRepo {
val ResultRow.asId: IdType
val selectById: ISqlExpressionBuilder.(IdType) -> Op<Boolean>
val selectByIds: ISqlExpressionBuilder.(List<IdType>) -> Op<Boolean>
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<IdType, Op<Boolean>?>(null) { id, acc ->
acc ?.or(selectById(id)) ?: selectById(id)
} ?: Op.FALSE
}
}