From 6ca76cff17eb52790fea1ef2ea2e2f3d477354f3 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 2 Jul 2022 19:34:58 +0300 Subject: [PATCH] Update output types of DataTree builders --- .../kscience/dataforge/data/DataTreeBuilder.kt | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/DataTreeBuilder.kt b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/DataTreeBuilder.kt index 316a8322..746c5501 100644 --- a/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/DataTreeBuilder.kt +++ b/dataforge-data/src/commonMain/kotlin/space/kscience/dataforge/data/DataTreeBuilder.kt @@ -21,8 +21,7 @@ public interface DataSourceBuilder : DataSetBuilder, DataSource { /** * A mutable [DataTree] that propagates updates */ -@PublishedApi -internal class DataTreeBuilder( +public class DataTreeBuilder( override val dataType: KType, coroutineContext: CoroutineContext, ) : DataTree, DataSourceBuilder { @@ -35,7 +34,7 @@ internal class DataTreeBuilder( override val items: Map> get() = treeItems.filter { !it.key.body.startsWith("@") } - override val updates = MutableSharedFlow() + override val updates: MutableSharedFlow = MutableSharedFlow() @Synchronized private fun remove(token: NameToken) { @@ -102,22 +101,18 @@ public fun DataSource( type: KType, parent: CoroutineScope, block: DataSourceBuilder.() -> Unit, -): DataSourceBuilder { - val tree = DataTreeBuilder(type, parent.coroutineContext) - tree.block() - return tree -} +): DataTreeBuilder = DataTreeBuilder(type, parent.coroutineContext).apply(block) @Suppress("OPT_IN_USAGE","FunctionName") public inline fun DataSource( parent: CoroutineScope, crossinline block: DataSourceBuilder.() -> Unit, -): DataSourceBuilder = DataSource(typeOf(), parent) { block() } +): DataTreeBuilder = DataSource(typeOf(), parent) { block() } @Suppress("FunctionName") public suspend inline fun DataSource( crossinline block: DataSourceBuilder.() -> Unit = {}, -): DataSourceBuilder = DataTreeBuilder(typeOf(), coroutineContext).apply { block() } +): DataTreeBuilder = DataTreeBuilder(typeOf(), coroutineContext).apply { block() } public inline fun DataSourceBuilder.emit( name: Name,