From 7d9189e15c3484e56b53f25db1c9b4ec9e66a055 Mon Sep 17 00:00:00 2001 From: darksnake Date: Sat, 7 May 2022 18:06:55 +0300 Subject: [PATCH] Replace T by Pair in data reducers --- .../space/kscience/dataforge/actions/ReduceAction.kt | 10 +++++----- .../space/kscience/dataforge/data/dataTransform.kt | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/ReduceAction.kt b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/ReduceAction.kt index 3e1ec62f..99da6cd2 100644 --- a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/ReduceAction.kt +++ b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/actions/ReduceAction.kt @@ -19,14 +19,14 @@ public class JoinGroup( public var meta: MutableMeta = MutableMeta() - public lateinit var result: suspend ActionEnv.(Map) -> R + public lateinit var result: suspend ActionEnv.(Map>) -> R - internal fun result(outputType: KType, f: suspend ActionEnv.(Map) -> R1) { + internal fun result(outputType: KType, f: suspend ActionEnv.(Map>) -> R1) { this.outputType = outputType this.result = f; } - public inline fun result(noinline f: suspend ActionEnv.(Map) -> R1) { + public inline fun result(noinline f: suspend ActionEnv.(Map>) -> R1) { outputType = typeOf() this.result = f; } @@ -66,7 +66,7 @@ public class ReduceGroupBuilder( /** * Apply transformation to the whole node */ - public fun result(resultName: String, f: suspend ActionEnv.(Map) -> R) { + public fun result(resultName: String, f: suspend ActionEnv.(Map>) -> R) { groupRules += { node -> listOf(JoinGroup(resultName, node, outputType).apply { result(outputType, f) }) } @@ -82,7 +82,7 @@ internal class ReduceAction( outputType: KType, private val action: ReduceGroupBuilder.() -> Unit, ) : CachingAction(outputType) { - //TODO optimize reduction. Currently the whole action recalculates on push + //TODO optimize reduction. Currently, the whole action recalculates on push override fun transform(set: DataSet, meta: Meta, key: Name): Sequence> = sequence { diff --git a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/dataTransform.kt b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/dataTransform.kt index b4e58c2d..aba33561 100644 --- a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/dataTransform.kt +++ b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/dataTransform.kt @@ -49,13 +49,13 @@ public inline fun Data.combine( public inline fun Collection>.reduceToData( coroutineContext: CoroutineContext = EmptyCoroutineContext, meta: Meta = Meta.EMPTY, - crossinline block: suspend (Collection) -> R, + crossinline block: suspend (List>) -> R, ): Data = Data( meta, coroutineContext, this ) { - block(map { it.await() }) + block(map { it.meta to it.await() }) } @DFInternal @@ -63,14 +63,14 @@ public fun Map>.reduceToData( outputType: KType, coroutineContext: CoroutineContext = EmptyCoroutineContext, meta: Meta = Meta.EMPTY, - block: suspend (Map) -> R, + block: suspend (Map>) -> R, ): Data = Data( outputType, meta, coroutineContext, this.values ) { - block(mapValues { it.value.await() }) + block(mapValues { it.value.meta to it.value.await() }) }