Updated on 2026-08-14
This commit is contained in:
parent
6a5a8300cf
commit
3269095c97
15 changed files with 148 additions and 96 deletions
|
|
@ -36,4 +36,16 @@ inline fun <T> Set<T>.addOrReplace(item: T, predicate: (T) -> Boolean): Set<T> {
|
|||
}
|
||||
|
||||
return mutableList
|
||||
}
|
||||
|
||||
inline fun <T> Set<T>.addOrReplace(items: Set<T>, predicate: (T, T) -> Boolean): Set<T> {
|
||||
val updatedValues = this.toMutableSet()
|
||||
|
||||
items.forEach { newValue ->
|
||||
val isReplaced = updatedValues.replaceBy(item = newValue, predicate = { predicate(it, newValue) })
|
||||
|
||||
if (!isReplaced) updatedValues.add(newValue)
|
||||
}
|
||||
|
||||
return updatedValues
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue