From 4a760630936525da2014f8014b716dde251df9ca Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 30 Jul 2021 19:56:31 +0300 Subject: [PATCH] add append methods for meta --- .../space/kscience/dataforge/meta/MutableMeta.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableMeta.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableMeta.kt index 0f820717..da822aa0 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableMeta.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/MutableMeta.kt @@ -384,19 +384,25 @@ private class MutableMetaImpl( * Append the node with a same-name-sibling, automatically generating numerical index */ @DFExperimental -public fun MutableMeta.append(name: Name, value: Value?) { +public fun MutableMeta.append(name: Name, meta: Meta) { require(!name.isEmpty()) { "Name could not be empty for append operation" } val newIndex = name.lastOrNull()!!.index if (newIndex != null) { - set(name, value) + set(name, meta) } else { val index = (getIndexed(name).keys.mapNotNull { it?.toIntOrNull() }.maxOrNull() ?: -1) + 1 - set(name.withIndex(index.toString()), value) + set(name.withIndex(index.toString()), meta) } } @DFExperimental -public fun MutableMeta.append(name: String, value: Value?): Unit = append(name.toName(), value) +public fun MutableMeta.append(name: String, meta: Meta): Unit = append(name.toName(), meta) + +@DFExperimental +public fun MutableMeta.append(name: Name, value: Value): Unit = append(name, Meta(value)) + +@DFExperimental +public fun MutableMeta.append(name: String, value: Value): Unit = append(name.toName(), value) ///** // * Apply existing node with given [builder] or create a new element with it.