Created
December 3, 2016 18:05
-
-
Save jbrains/ff3065f4abe0d8d0a7effb8f86c1b122 to your computer and use it in GitHub Desktop.
PLEASE tell me that there's a better way in Java to write this
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
// findPrice : String -> Option<Price> | |
// Option comes from Atlassian's fugue library https://docs.atlassian.com/fugue/4.3.0/fugue/apidocs/index.html | |
// I want the equivalent of | |
// case (maybePrice) { | |
// none => display.displayProductNotFoundMessage(barcode) | |
// some(price) => display.displayPrice(price) | |
// } | |
catalog.findPrice(barcode) | |
.<Runnable>fold( | |
() -> (() -> display.displayProductNotFoundMessage(barcode)), | |
(price) -> (() -> display.displayPrice(price)) | |
).run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My two minutes attempt, using Functional Java. Obviously, untested and from the top of my head!
If the only side effect is printing a String, we could simplify it like this: