K2: introduce & use (for annotation creation) smartPlus for lists

This commit is contained in:
Mikhail Glukhikh
2022-12-19 17:21:58 +01:00
committed by Space Team
parent f33f87e3d4
commit 761a0f8248
5 changed files with 16 additions and 24 deletions
@@ -197,3 +197,14 @@ value class MutableOrEmptyList<T>(val list: MutableList<T>?) : List<T> {
fun <T> empty(): MutableOrEmptyList<T> = EMPTY as MutableOrEmptyList<T>
}
}
fun <T> List<T>.smartPlus(other: List<T>): List<T> = when {
other.isEmpty() -> this
this.isEmpty() -> other
else -> {
val result = ArrayList<T>(this.size + other.size)
result.addAll(this)
result.addAll(other)
result
}
}