question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide TreeTraverser.fromFunction(Function)

See original GitHub issue

Instead 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:closed
  • Created 9 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ronshapirocommented, Oct 9, 2017

I believe this is taken care of by common.graph.Traverser.forTree(SuccessorsFunction) once it’s implemented (which should be very soon)

0reactions
kevinb9ncommented, Sep 25, 2016

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:

I see this has been completed now (at least to some extent).

Does any more work need to be done on this (like doing a lambda version of BinaryTreeTraverser)? Or can this issue be closed now?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/google/guava/issues/2006#issuecomment-249380776, or mute the thread https://github.com/notifications/unsubscribe-auth/AA5Cl867VAMPT1_BRLFPAn9vfXNb73M3ks5qtW9UgaJpZM4DxV_S .

Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb@google.com

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found