Skip to content

Instantly share code, notes, and snippets.

@joshiraez
Created January 1, 2020 03:30
Show Gist options
  • Save joshiraez/ed54896863a9e6431813c1b77fcf229d to your computer and use it in GitHub Desktop.
Save joshiraez/ed54896863a9e6431813c1b77fcf229d to your computer and use it in GitHub Desktop.
Example Operator interface for "Rethinking Interfaces" in Medium
import java.util.List;
interface Operation {
boolean isOperation (String input);
int operate (List<Integer> numbers);
}
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