Replace branch data builder with putAll

This commit is contained in:
Alexander Nozik 2024-02-19 11:41:27 +03:00
parent f95e278b2d
commit aa88f05688

View File

@ -98,15 +98,15 @@ public val DataTree<*>.meta: Meta? get() = data?.meta
/** /**
* Provide subtree if it exists * Provide subtree if it exists
*/ */
public tailrec fun <T, TR : GenericDataTree<T, TR>> GenericDataTree<T, TR>.putAll(name: Name): TR? = public tailrec fun <T, TR : GenericDataTree<T, TR>> GenericDataTree<T, TR>.branch(name: Name): TR? =
when (name.length) { when (name.length) {
0 -> self 0 -> self
1 -> items[name.first()] 1 -> items[name.first()]
else -> items[name.first()]?.putAll(name.cutFirst()) else -> items[name.first()]?.branch(name.cutFirst())
} }
public fun <T, TR : GenericDataTree<T, TR>> GenericDataTree<T, TR>.putAll(name: String): TR? = public fun <T, TR : GenericDataTree<T, TR>> GenericDataTree<T, TR>.branch(name: String): TR? =
this@branch.putAll(name.parseAsName()) branch(name.parseAsName())
public fun GenericDataTree<*, *>.isEmpty(): Boolean = data == null && items.isEmpty() public fun GenericDataTree<*, *>.isEmpty(): Boolean = data == null && items.isEmpty()