Skip to content

Commit 982a772

Browse files
committed
Iterable utilities + squash another bug
1 parent 7a34d38 commit 982a772

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

compiler-plugin/src/main/kotlin/OverflowChecker.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class OverflowChecker(private val context: IrPluginContext, private val config:
8585
val collection = expression.extensionReceiver ?: error("Expected extension receiver")
8686

8787
if (expression.valueArgumentsCount == 0) {
88+
val type = collection.type
89+
if (type != context.irBuiltIns.intType && type != context.irBuiltIns.longType) return super.visitCall(expression)
90+
8891
return context.irBuiltIns
8992
.createIrBuilder(expression.symbol, expression.startOffset, expression.endOffset)
9093
.irCall(

src/main/kotlin/sschr15/aocsolutions/util/IterableUtils.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ inline fun <T, R> Iterable<T>.mapParallel(crossinline transform: suspend (T) ->
130130
map { async(Dispatchers.Default) { transform(it) } }.awaitAll()
131131
}
132132

133+
inline fun <T, R> Iterable<T>.mapIndexedParallel(crossinline transform: suspend (Int, T) -> R): List<R> = runBlocking {
134+
mapIndexed { index, t -> async(Dispatchers.Default) { transform(index, t) } }.awaitAll()
135+
}
136+
137+
inline fun <K, V> Iterable<Map<K, V>>.combineMaps(): Map<K, List<V>> {
138+
val result = mutableMapOf<K, MutableList<V>>()
139+
for (map in this) {
140+
for ((key, value) in map) {
141+
result.getOrPut(key) { mutableListOf() }.add(value)
142+
}
143+
}
144+
return result
145+
}
146+
133147
fun <A : Any, B> Iterable<Pair<A?, B>>.filterFirstNotNull() = filter { it.first != null }.map { it.first!! to it.second }
134148
fun <A, B : Any> Iterable<Pair<A, B?>>.filterSecondNotNull() = filter { it.second != null }.map { it.first to it.second!! }
135149

0 commit comments

Comments
 (0)