mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-01-13 03:09:56 +00:00
diff/applyDiff
This commit is contained in:
parent
feb695caa7
commit
3e3fbd97eb
3
.gitignore
vendored
3
.gitignore
vendored
@ -14,3 +14,6 @@ local.properties
|
|||||||
kotlin-js-store
|
kotlin-js-store
|
||||||
|
|
||||||
publishing.sh
|
publishing.sh
|
||||||
|
|
||||||
|
local.*
|
||||||
|
local/
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
## 0.20.49
|
## 0.20.49
|
||||||
|
|
||||||
|
* `Repos`:
|
||||||
|
* `Common`:
|
||||||
|
* All `Repo`s get `diff` extensions
|
||||||
|
* `KeyValueRepo` and `KeyValuesRepo` get `applyDiff` extension
|
||||||
|
|
||||||
## 0.20.48
|
## 0.20.48
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package dev.inmo.micro_utils.repos.diff
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.MapDiff
|
||||||
|
import dev.inmo.micro_utils.common.applyDiff
|
||||||
|
import dev.inmo.micro_utils.common.diff
|
||||||
|
import dev.inmo.micro_utils.repos.CRUDRepo
|
||||||
|
import dev.inmo.micro_utils.repos.ReadCRUDRepo
|
||||||
|
import dev.inmo.micro_utils.repos.unset
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> ReadCRUDRepo<Registered, Id>.diff(other: Map<Id, Registered>): MapDiff<Id, Registered> {
|
||||||
|
return getAll().diff(other)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> Map<Id, Registered>.diff(other: ReadCRUDRepo<Registered, Id>): MapDiff<Id, Registered> {
|
||||||
|
return diff(other.getAll())
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> MutableMap<Id, Registered>.applyDiff(other: ReadCRUDRepo<Registered, Id>) {
|
||||||
|
applyDiff(diff(other))
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package dev.inmo.micro_utils.repos.diff
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.MapDiff
|
||||||
|
import dev.inmo.micro_utils.common.applyDiff
|
||||||
|
import dev.inmo.micro_utils.common.diff
|
||||||
|
import dev.inmo.micro_utils.repos.KeyValueRepo
|
||||||
|
import dev.inmo.micro_utils.repos.ReadKeyValueRepo
|
||||||
|
import dev.inmo.micro_utils.repos.unset
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> ReadKeyValueRepo<Id, Registered>.diff(other: Map<Id, Registered>): MapDiff<Id, Registered> {
|
||||||
|
return getAll().diff(other)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> Map<Id, Registered>.diff(other: ReadKeyValueRepo<Id, Registered>): MapDiff<Id, Registered> {
|
||||||
|
return diff(other.getAll())
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> KeyValueRepo<Id, Registered>.applyDiff(diff: MapDiff<Id, Registered>) {
|
||||||
|
unset(diff.removed.map { it.key })
|
||||||
|
set(
|
||||||
|
diff.changed.map { (k, oldNew) ->
|
||||||
|
k to oldNew.second
|
||||||
|
}.toMap() + diff.added
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> KeyValueRepo<Id, Registered>.applyDiff(other: Map<Id, Registered>) {
|
||||||
|
applyDiff(diff(other))
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> MutableMap<Id, Registered>.applyDiff(other: ReadKeyValueRepo<Id, Registered>) {
|
||||||
|
applyDiff(diff(other))
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package dev.inmo.micro_utils.repos.diff
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.MapDiff
|
||||||
|
import dev.inmo.micro_utils.common.applyDiff
|
||||||
|
import dev.inmo.micro_utils.common.diff
|
||||||
|
import dev.inmo.micro_utils.repos.*
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> ReadKeyValuesRepo<Id, Registered>.diff(other: Map<Id, List<Registered>>): MapDiff<Id, List<Registered>> {
|
||||||
|
return getAll().diff(other)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> Map<Id, List<Registered>>.diff(other: ReadKeyValuesRepo<Id, Registered>): MapDiff<Id, List<Registered>> {
|
||||||
|
return diff(other.getAll())
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> KeyValuesRepo<Id, Registered>.applyDiff(diff: MapDiff<Id, List<Registered>>) {
|
||||||
|
diff.removed.forEach {
|
||||||
|
clear(it.key)
|
||||||
|
}
|
||||||
|
set(
|
||||||
|
diff.changed.map { (k, oldNew) ->
|
||||||
|
k to oldNew.second
|
||||||
|
}.toMap() + diff.added
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> KeyValuesRepo<Id, Registered>.applyDiff(other: Map<Id, List<Registered>>) {
|
||||||
|
applyDiff(diff(other))
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <Id, Registered> MutableMap<Id, List<Registered>>.applyDiff(other: ReadKeyValuesRepo<Id, Registered>) {
|
||||||
|
applyDiff(diff(other))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user