With Collection
everything is clear, but what about the following:
There is an object
with a count()
method and a getPart(int i)
method. So extracting all objects leads to the following boilerplate code:
List<Part> result = new ArrayList<Part>();
for (int i = 0, i < object.count(), i++) {
result.add(object.getPart(i));
}
return result.stream();
Is there any standard way to pass just 2 producers: () -> object.count()
and (int i) -> object.getPart(i)
to create a stream? Like this:
SomeUtil.stream(object::count, object::getPart);