mapNode<T> static method
List<TreeNode<T> >
mapNode<T>(
- List<
TreeNode< nodes,T> > - TreeNodeId id,
- TreeNode<
T> transform(- TreeNode<
T>
- TreeNode<
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)),
];
}