rootMostValueMatching method
The root-most value on relativePath matching predicate, or null.
Implementation
T? rootMostValueMatching(
Path relativePath,
bool Function(T value) predicate,
) {
final T? value = this.value;
if (value != null && predicate(value)) {
return value;
}
ImmutableTree<T> current = this;
for (final ChildKey key in relativePath.segments) {
final ImmutableTree<T>? next = current.children[key];
if (next == null) {
return null;
}
final T? nextValue = next.value;
if (nextValue != null && predicate(nextValue)) {
return nextValue;
}
current = next;
}
return null;
}