Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recursive Tree factory methods #1640

Closed
danieldietrich opened this issue Oct 25, 2016 · 2 comments
Closed

Add recursive Tree factory methods #1640

danieldietrich opened this issue Oct 25, 2016 · 2 comments

Comments

@danieldietrich
Copy link
Contributor

danieldietrich commented Oct 25, 2016

I described it in the blog-post Object-Functional Concurrent Programming with Javaslang.

Signatures:

Node<T> of(T seed,  Function<? super T, Iterable<? extends T>> descend);

Future<Node<T>> ofAsync(T seed,  Function<? super T, Future<? extends Iterable<? extends T>>> descend);

Depends on: #1529

Example impl:

static <T> Future<Node<T>> ofAsync(T seed,  
        Function<? super T, Future<? extends Iterable<? extends T>>>
        descend) {
    return Future.of(promise -> descend.apply(seed)
        .onComplete(result -> result
            .onSuccess(children -> promise.completeWith(
                Future.sequence(
                    Iterator.ofAll(children).map(child -> ofAsync(child, descend))
                ).map(childNodes -> Tree.of(seed, childNodes))))
            .onFailure(promise::failure)));
}
@danieldietrich danieldietrich added this to the 2.1.0 milestone Oct 25, 2016
@danieldietrich danieldietrich changed the title Add recursive Tree factory methods of and ofAsync Add recursive Tree factory methods Nov 11, 2016
@danieldietrich danieldietrich modified the milestones: 3.0.0, 2.1.0 Mar 4, 2017
@danieldietrich
Copy link
Contributor Author

Maybe this should be closed. The module vavr-collectionx should not depend on vavr-concurrent.

@danieldietrich
Copy link
Contributor Author

The sync case is fixed with #2121. We will not do the async case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant