Created
January 1, 2020 03:30
-
-
Save joshiraez/ed54896863a9e6431813c1b77fcf229d to your computer and use it in GitHub Desktop.
Example Operator interface for "Rethinking Interfaces" in Medium
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
import java.util.List; | |
interface Operation { | |
boolean isOperation (String input); | |
int operate (List<Integer> numbers); | |
} |
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
class Sum implements Operation { | |
public boolean isOperation(String operator) { | |
return operator.equals("+"); | |
} | |
public int operate (List<Integer> numbers) { | |
return numbers | |
.stream() | |
.mapToInt(Integer::intValue) | |
.reduce( | |
(a,b) -> a+b | |
).getAsInt(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment