bdawg.io
10/26/2017, 11:21 PMfilters[property]
if merging two nullable sets yields a non-empty set
1️⃣
val additional: Set<T>? = filterStates[requested]
if (additional is Set<*> && additional.isNotEmpty()) {
val current: Set<T>? = filters[property]
if (current is Set<*> && current.isNotEmpty()) {
filters[property] = current.plus(additional)
} else {
filters[property] = additional
}
}
2️⃣ filters[property].plusMaybe(filterStates[requested.value])?.let {
filters[property] = it
}
fun <T : Any> Set<T>?.plusMaybe(other: Set<T>?): Set<T>? = (this ?: emptySet()).plus(other ?: emptySet()).takeIf { it.isNotEmpty() }
diesieben07
10/26/2017, 11:27 PMval new = (filterStates[requested] ?: emptySet()) + (filters[property] ?: emptySet())
if (new.isNotEmpty()) {
filters[property] = new
}
bdawg.io
10/26/2017, 11:33 PMfilters[property]
it wouldn’t be an issue in the case of a backing fielddiesieben07
10/26/2017, 11:33 PMbdawg.io
10/26/2017, 11:34 PMfilterStates[requested]
yields null, it will short circuit from doing the assignment altogetherdiesieben07
10/26/2017, 11:35 PMbdawg.io
10/26/2017, 11:36 PM