Last active
July 30, 2017 18:34
-
-
Save nachivpn/c26f1c37e40653a7f7ceefe504405cba to your computer and use it in GitHub Desktop.
findOriginalPrice.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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