Skip to content

Instantly share code, notes, and snippets.

@nachivpn
Last active July 30, 2017 18:34
Show Gist options
  • Save nachivpn/c26f1c37e40653a7f7ceefe504405cba to your computer and use it in GitHub Desktop.
Save nachivpn/c26f1c37e40653a7f7ceefe504405cba to your computer and use it in GitHub Desktop.
findOriginalPrice.java
Map<String,Double> prices;
//return price of component if available, else return exception
public Either<Exception,Double> findOriginalPrice(String componentId){
Optional<Double> optionalPrice = Optional.ofNullable(prices.get(componentId));
return optionalPrice
.<Either<Exception,Double>>map(price -> new Right<>(price))
.orElse(new Left<>(new Exception("Price not found for " + componentId)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment