mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-26 03:58:45 +00:00
now applyDiff will return its receiver
This commit is contained in:
parent
149a1aa278
commit
c9872a61b6
@ -76,15 +76,17 @@ fun <K, V> Map<K, V>.diff(
|
|||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will apply changes with [other] map into [this] one
|
* Will apply changes with [from] map into [this] one
|
||||||
*
|
*
|
||||||
* @param compareFun Will be used to determine changed values
|
* @param compareFun Will be used to determine changed values
|
||||||
|
*
|
||||||
|
* @return [MapDiff] applied to [this] [MutableMap]
|
||||||
*/
|
*/
|
||||||
fun <K, V> MutableMap<K, V>.applyDiff(
|
fun <K, V> MutableMap<K, V>.applyDiff(
|
||||||
from: Map<K, V>,
|
from: Map<K, V>,
|
||||||
compareFun: (K, V, V) -> Boolean
|
compareFun: (K, V, V) -> Boolean
|
||||||
) {
|
): MapDiff<K, V> {
|
||||||
diff(from, compareFun).apply {
|
return diff(from, compareFun).apply {
|
||||||
removed.keys.forEach { remove(it) }
|
removed.keys.forEach { remove(it) }
|
||||||
changed.forEach { (k, oldNew) ->
|
changed.forEach { (k, oldNew) ->
|
||||||
put(k, oldNew.second)
|
put(k, oldNew.second)
|
||||||
@ -96,15 +98,17 @@ fun <K, V> MutableMap<K, V>.applyDiff(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will apply changes with [other] map into [this] one
|
* Will apply changes with [from] map into [this] one
|
||||||
*
|
*
|
||||||
* @param strictComparison If true, will use strict (===) comparison for the values' comparison. Otherwise, standard
|
* @param strictComparison If true, will use strict (===) comparison for the values' comparison. Otherwise, standard
|
||||||
* `equals` will be used
|
* `equals` will be used
|
||||||
|
*
|
||||||
|
* @return [MapDiff] applied to [this] [MutableMap]
|
||||||
*/
|
*/
|
||||||
fun <K, V> MutableMap<K, V>.applyDiff(
|
fun <K, V> MutableMap<K, V>.applyDiff(
|
||||||
other: Map<K, V>,
|
from: Map<K, V>,
|
||||||
strictComparison: Boolean = false
|
strictComparison: Boolean = false
|
||||||
) = applyDiff(
|
): MapDiff<K, V> = applyDiff(
|
||||||
other,
|
from,
|
||||||
compareFun = createCompareFun(strictComparison)
|
compareFun = createCompareFun(strictComparison)
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user