I'm not sure if a question was already asked. I'm still new to Java's Stream API and Google's Guava.
I would like to use Java's Stream API to transform or map one object to another one item at a time. It seems like this is different than collect. It seems like collect would convert all items in the stream when it's called instead of one at a time. Ideally, I would like to provide an iterable that allows one item to be converted when something like next() is called.
Maybe it would look something like this:
private Iterable<ObjectA> getIterable(Iterable<ObjectB> itemsToConvert) {
return itemsToConvert.map(mappingFunction);
}
public static void main(String[] args) {
Iterable<ObjectA> myIterable = getIterable(itemsFromSomewhere);
// do the conversion here
ObjectA myItem = myIterable.next();
}
Is there a way to do this in Java using the Stream API? If not, is there a way to do this using Google's Guava?