Last active
July 14, 2016 13:42
-
-
Save afcastano/90ddfd7c9b4c861c9cf7f7d617d4c628 to your computer and use it in GitHub Desktop.
Monadic way of dealing with colour count.
This file contains 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
private abstract Optional<Counter> fetchThisMonthCounts(); | |
private abstract Optional<Counter> fetchPreviousMonthCounts(); | |
public Optional<Integer> totalColour() { | |
return fetchThisMonthCounts().flatMap(Counter::colour).flatMap(colour1 -> | |
fetchPreviousMonthCounts().flatMap(Counter::colour).flatMap(colour2 -> | |
Optional.of(colour1 + colour2) | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment