now applyDiff will return its receiver

This commit is contained in:
InsanusMokrassar 2023-05-05 11:49:09 +06:00
parent 149a1aa278
commit c9872a61b6

View File

@ -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)
) )