Skip to content

Instantly share code, notes, and snippets.

@muthuishere
Last active August 14, 2021 08:59
Show Gist options
  • Save muthuishere/5c0c8970a64e301ed92b65127d5c9dab to your computer and use it in GitHub Desktop.
Save muthuishere/5c0c8970a64e301ed92b65127d5c9dab to your computer and use it in GitHub Desktop.
Declarativex
results= Try.from(()->newsService.downloadFromNyTimes(topic))
.or(()->newsService.downloadFromHerald(topic))
.or(()->newsService.downloadFromSun(topic))
.get();
results= Try.any(newsService::downloadFromNyTimes,
newsService::downloadFromHerald,
newsService::downloadFromSun)
.with(topic)
.get();
List<String> results = null;
try {
results =newsService.downloadFromNyTimes(topic);
}catch (Exception e){
try {
results =newsService.downloadFromHerald(topic);
}catch (Exception e1){
try {
results =newsService.downloadFromSun(topic);
}catch (Exception ignored){
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment