public <A> A collectFirst(Function<BaseType, A> f) {
        Wrapper wrapper = new Wrapper();
        this.foreach(node -> {
            if (wrapper.value == null) {
                A res = f.apply(node);
                if (res != null) {
                    wrapper.value = res;
                }
            }
        });
        return (A) wrapper.value;
    }
Collect the elements produced by `f` and not null.
indexr-query-opt/src/main/java/io/indexr/query/TreeNode.java