Remove obsolete getData for DataSet

This commit is contained in:
Alexander Nozik 2022-05-01 19:29:13 +03:00
parent 82d37f4b55
commit 665f317e4e
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
8 changed files with 31 additions and 22 deletions

View File

@ -27,13 +27,20 @@ public data class ActionEnv(
* Action environment
*/
@DFBuilder
public class MapActionBuilder<T, R>(public var name: Name, public var meta: MutableMeta, public val actionMeta: Meta) {
public class MapActionBuilder<T, R>(
public var name: Name,
public var meta: MutableMeta,
public val actionMeta: Meta,
public var outputType: KType
) {
public lateinit var result: suspend ActionEnv.(T) -> R
/**
* Calculate the result of goal
*/
public fun result(f: suspend ActionEnv.(T) -> R) {
public inline fun <reified R1: R> result(noinline f: suspend ActionEnv.(T) -> R1) {
outputType = typeOf<R1>()
result = f;
}
}
@ -57,7 +64,8 @@ internal class MapAction<in T : Any, out R : Any>(
val builder = MapActionBuilder<T, R>(
data.name,
data.meta.toMutableMeta(), // using data meta
meta
meta,
outputType
).apply(block)
//getting new name
@ -67,7 +75,7 @@ internal class MapAction<in T : Any, out R : Any>(
val newMeta = builder.meta.seal()
@OptIn(DFInternal::class)
val newData = Data(outputType, newMeta, dependencies = listOf(data)) {
val newData = Data(builder.outputType, newMeta, dependencies = listOf(data)) {
builder.result(env, data.await())
}
//setting the data node

View File

@ -73,8 +73,6 @@ public interface DataTree<out T : Any> : DataSet<T> {
}
}
public suspend fun <T : Any> DataSet<T>.getData(name: String): Data<T>? = get(Name.parse(name))
/**
* Get a [DataTreeItem] with given [name] or null if the item does not exist
*/

View File

@ -9,6 +9,9 @@ public interface NamedData<out T : Any> : Named, Data<T> {
public val data: Data<T>
}
public operator fun NamedData<*>.component1(): Name = name
public operator fun <T: Any> NamedData<T>.component2(): Data<T> = data
private class NamedDataImpl<out T : Any>(
override val name: Name,
override val data: Data<T>,

View File

@ -24,7 +24,7 @@ internal class ActionsTest {
}
runBlocking {
val result = plusOne.execute(data)
assertEquals(2, result.getData("1")?.await())
assertEquals(2, result["1"]?.await())
}
}
@ -36,7 +36,7 @@ internal class ActionsTest {
val datum = runBlocking {
val result = plusOne.execute(data, scope = this)
result.getData("1")?.await()
result["1"]?.await()
}
assertEquals(2, datum)
}

View File

@ -19,10 +19,10 @@ internal class DataTreeBuilderTest {
static("c.f", "c.f")
}
runBlocking {
assertEquals("a", node.getData("primary.a")?.await())
assertEquals("b", node.getData("primary.b")?.await())
assertEquals("c.d", node.getData("c.d")?.await())
assertEquals("c.f", node.getData("c.f")?.await())
assertEquals("a", node["primary.a"]?.await())
assertEquals("b", node["primary.b"]?.await())
assertEquals("c.d", node["c.d"]?.await())
assertEquals("c.f", node["c.f"]?.await())
}
}
@ -46,8 +46,8 @@ internal class DataTreeBuilderTest {
}
runBlocking {
assertEquals("a", node.getData("update.a")?.await())
assertEquals("a", node.getData("primary.a")?.await())
assertEquals("a", node.get("update.a")?.await())
assertEquals("a", node.get("primary.a")?.await())
}
}
@ -80,7 +80,7 @@ internal class DataTreeBuilderTest {
}
}
updateJob.join()
assertEquals(9, rootNode.getData("sub.value")?.await())
assertEquals(9, rootNode["sub.value"]?.await())
cancel()
}
} catch (t: Throwable) {

View File

@ -23,7 +23,7 @@ class DataPropagationTestPlugin : WorkspacePlugin() {
val singleData by task<Int> {
workspace.data.select<Int>().getData("myData[12]")?.let {
workspace.data.select<Int>()["myData[12]"]?.let {
data("result", it)
}
}

View File

@ -68,8 +68,8 @@ class FileDataTest {
writeDataDirectory(dir, dataNode, StringIOFormat)
println(dir.toUri().toString())
val reconstructed = readDataDirectory(dir, StringFormatResolver)
assertEquals(dataNode.getData("dir.a")?.meta, reconstructed.getData("dir.a")?.meta)
assertEquals(dataNode.getData("b")?.await(), reconstructed.getData("b")?.await())
assertEquals(dataNode["dir.a"]?.meta, reconstructed["dir.a"]?.meta)
assertEquals(dataNode["b"]?.await(), reconstructed["b"]?.await())
}
}
}
@ -84,8 +84,8 @@ class FileDataTest {
writeZip(zip, dataNode, StringIOFormat)
println(zip.toUri().toString())
val reconstructed = readDataDirectory(zip, StringFormatResolver)
assertEquals(dataNode.getData("dir.a")?.meta, reconstructed.getData("dir.a")?.meta)
assertEquals(dataNode.getData("b")?.await(), reconstructed.getData("b")?.await())
assertEquals(dataNode["dir.a"]?.meta, reconstructed["dir.a"]?.meta)
assertEquals(dataNode["b"]?.await(), reconstructed["b"]?.await())
}
}
}

View File

@ -134,8 +134,8 @@ class SimpleWorkspaceTest {
val delta by task<Int> {
val averaged = from(averageByGroup)
val even = averaged.getData("event")!!
val odd = averaged.getData("odd")!!
val even = averaged["event"]!!
val odd = averaged["odd"]!!
val res = even.combine(odd) { l, r ->
l - r
}