commonMain.dev.inmo.micro_utils.repos.diff.KeyValuesRepoDiff.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micro_utils.repos.common-jvm Show documentation
Show all versions of micro_utils.repos.common-jvm Show documentation
It is set of projects with micro tools for avoiding of routines coding
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 ReadKeyValuesRepo.diff(other: Map>): MapDiff> {
return getAll().diff(other)
}
suspend fun Map>.diff(other: ReadKeyValuesRepo): MapDiff> {
return diff(other.getAll())
}
suspend fun KeyValuesRepo.applyDiff(diff: MapDiff>) {
diff.removed.forEach {
clear(it.key)
}
set(
diff.changed.map { (k, oldNew) ->
k to oldNew.second
}.toMap() + diff.added
)
}
suspend fun KeyValuesRepo.applyDiff(other: Map>) {
applyDiff(diff(other))
}
suspend fun MutableMap>.applyDiff(other: ReadKeyValuesRepo) {
applyDiff(diff(other))
}