Provide TreeTraverser.fromFunction(Function)
See original GitHub issueInstead of implementing TreeTraverser.children(T) in anonymous classes each time a function that retrieves children from each node could be handy also.
What about this static method at TreeTraverser
static <T> TreeTraverser<T> fromFunction(final Function<? super T, ? extends Iterable<? extends T>> descendants) {
return new TreeTraverser (...);
}
and a possible implementation as proposal.
/**
* @see Traversers#fromFunction(Function)
*/
static final class TreeTraverserFromFunction<T> extends TreeTraverser<T> {
private final Function<? super T, ? extends Iterable<? extends T>> descendants;
TreeTraverserFromFunction(final Function<? super T, ? extends Iterable<? extends T>> children) {
descendants = checkNotNull(children);
}
@Override
public Iterable<T> children(final T root) {
@SuppressWarnings("unchecked")
final Iterable<T> checkedIterable = (Iterable<T>) descendants.apply(root);
return checkedIterable;
}
@Override
public String toString() {
return "TreeTraverser.fromFunction(" + descendants + ")";
}
}
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
numpy.fromfunction — NumPy v1.23 Manual
Construct an array by executing a function over each coordinate. The resulting array therefore has a value fn(x, y, z) at coordinate (x ......
Read more >Uses of Interface com.google.common.base.Function - Guava
Returns a converter based on separate forward and backward functions. static <A,B> Converter<A,B>, Converter. from(Function<?
Read more >numpy.fromfunction() function – Python - GeeksforGeeks
fromfunction () function construct an array by executing a function over each coordinate and the resulting array, therefore, has a value fn(x, y, ......
Read more >Guava: Google Core Libraries for Java 24.1.1-android API
Provided to satisfy the Function interface; use Converter.convert(A) instead. ... from(Function<K, V>) - Static method in class com.google.common.cache.
Read more >On Lisp
possibilities they offer. Chapter 3 then discusses the advantages of functional programming, the dominant style in Lisp programs. Chapter 4 shows how to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe this is taken care of by
common.graph.Traverser.forTree(SuccessorsFunction)
once it’s implemented (which should be very soon)Yeah, we still need to do it for BinaryTreeTraverser too.
On Sat, Sep 24, 2016 at 11:43 AM, Jonathan Bluett-Duncan < notifications@github.com> wrote:
Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb@google.com