removeNode<T> static method

List<TreeNode<T>> removeNode<T>(
  1. List<TreeNode<T>> nodes,
  2. TreeNodeId id
)

Rebuild nodes with id (and its subtree) removed.

Implementation

static List<TreeNode<T>> removeNode<T>(List<TreeNode<T>> nodes, TreeNodeId id) {
  final out = <TreeNode<T>>[];
  for (final n in nodes) {
    if (n.id == id) continue;
    out.add(n.children.isEmpty ? n : n.copyWith(children: removeNode<T>(n.children, id)));
  }
  return out;
}