mapNode<T> static method

List<TreeNode<T>> mapNode<T>(
  1. List<TreeNode<T>> nodes,
  2. TreeNodeId id,
  3. TreeNode<T> transform(
    1. TreeNode<T>
    )
)

Rebuild nodes, replacing the node matching id with transform(node).

Implementation

static List<TreeNode<T>> mapNode<T>(List<TreeNode<T>> nodes, TreeNodeId id, TreeNode<T> Function(TreeNode<T>) transform) {
  return [
    for (final n in nodes)
      if (n.id == id)
        transform(n)
      else if (n.children.isEmpty)
        n
      else
        n.copyWith(children: mapNode<T>(n.children, id, transform)),
  ];
}