Support sam conversion in ir interpreter

This commit is contained in:
Ivan Kylchik
2021-08-05 13:12:52 +03:00
committed by TeamCityServer
parent b85a796492
commit 23b315446f
12 changed files with 156 additions and 22 deletions
+10
View File
@@ -136,6 +136,16 @@ public fun <T, C : MutableCollection<in T>> Iterable<T>.toCollection(destination
return destination
}
public inline fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> {
return mapTo(ArrayList<R>(if (this is Collection<*>) this.size else 10), transform)
}
public inline fun <T, R, C : MutableCollection<in R>> Iterable<T>.mapTo(destination: C, transform: (T) -> R): C {
for (item in this)
destination.add(transform(item))
return destination
}
internal fun <T> List<T>.optimizeReadOnlyList() = when (size) {
0 -> emptyList()
1 -> listOf(this[0])