Skip to content

Instantly share code, notes, and snippets.

@michaelamaura
Created August 21, 2015 09:27
Show Gist options
  • Save michaelamaura/8e361c8404b6d835985c to your computer and use it in GitHub Desktop.
Save michaelamaura/8e361c8404b6d835985c to your computer and use it in GitHub Desktop.
Coalesce of suppliers
public class Misc {
public static <T> T coalesce(Supplier<T>... ts) {
return Arrays.asList(ts)
.stream()
.map(Supplier::get)
.filter(Objects::nonNull)
.findFirst()
.orElse(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment