filter

fun filter(predicate: (T) -> Boolean): TreeNode<T>?

Filters the tree based on a given predicate.

Return

A new TreeNode containing only the nodes that satisfy the predicate, or null if the root node does not satisfy the predicate.

Parameters

predicate

A function that evaluates each node's value to determine if it should be included.