Skip to content

Instantly share code, notes, and snippets.

@mchmielarz
Last active December 17, 2018 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchmielarz/3eb23ad94a747029b721d4e4a7043e4d to your computer and use it in GitHub Desktop.
Save mchmielarz/3eb23ad94a747029b721d4e4a7043e4d to your computer and use it in GitHub Desktop.
Read geo coordinates from a file with recovery
Try.of(
() -> geoCoordinatesReader.fromCsvFile("./src/main/resources/cities.csv")
)
.onSuccess(coords -> log.info("Coordinates read: {}", coords))
  .onFailure(exc -> log.error("Cannot read coordinates from a file", exc))
  .recover(FileNotFoundException.class, (exc) -> provideBackupCoordinates())
  .getOrElse(List.empty());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment