Hi Jason, On Thu, 2018-05-31 at 10:39 -0400, Jason E Bailey wrote: > https://github.com/apache/sling-org-apache-sling-api/pull/4 > > I've created a pull request to add a new class to the Sling API > bundle that would allow you to create a Stream<Resource> object which > traverses a resource tree. > > Additionally, the ResourceStream class has convenience methods to > specify a predicate that identifies valid resources, a limit to the > number of valid items that are returned and a range method. There is > also a core feature of branch selection that allows you to customize > the traversal so that it you can limit the branches that the > traversal proceeds down. > > If you have concerns or questions, now's the time to raise it.
Again, thanks for looking into this, I think it's a nice addition. There are two questions I want to raise: 1. API related We have two methods: - stream() - stream(Predicate<Resource>) which traverse the whole tree. There were questions of whether this is OK or if we maybe need to stream the children only. Could the API additions allow that? We can start with something like - stream(Predicate<Resource>, Set<TraversalOption>... ) - stream(Predicate<Resource>) - stream(Set<TraversalOption>...) where enum TraversalOption { DIRECT_CHILDREN_ONLY, ALL_CHILDREN; } (yes, the names are bad, just wanted to raise the question and start a discussion) 2. Implementation related I think that the 'hasNext' method is not lazy, eagerly loading the direct children of a resource when there are no more resources to load. If the resource has a large number of children we can end up taking lots of memory, so I think we need to be more lazy with it, since the streams framework can take advantage of that (IIRC). Is it possible to ajust the implementation this way? Thanks, Robert