I’m looking for a Google Collections method that returns the first result of a sequence of Suppliers that doesn’t return null.
I was looking at using Iterables.find() but in my Predicate I would have to call my supplier to compare the result against null, and then have to call it again once the find method returned the supplier.
Given your comment to Calm Storm’s answer (the desire not to call
Supplier.get()twice), then what about:then
note that the Iterable that comes out of
Iterables.transform()is lazily-evaluated, therefore asIterables.find()loops over it, you only evaluate as far as the first non-null-returning one, and that only once.