set method

ImmutableTree<T> set(
  1. Path relativePath,
  2. T? toSet
)

A tree with toSet at relativePath.

Implementation

ImmutableTree<T> set(Path relativePath, T? toSet) {
  if (relativePath.isEmpty) {
    return ImmutableTree<T>._(toSet, children);
  }
  final ChildKey front = relativePath.front!;
  final ImmutableTree<T> child = children[front] ?? ImmutableTree<T>.empty();
  final ImmutableTree<T> newChild = child.set(relativePath.popFront(), toSet);
  return ImmutableTree<T>._(value, children.insert(front, newChild));
}