Skip to content

Instantly share code, notes, and snippets.

@adam-arold
Created September 11, 2017 16:36
Show Gist options
  • Save adam-arold/9276ed18fec50fa4bdf030139e813572 to your computer and use it in GitHub Desktop.
Save adam-arold/9276ed18fec50fa4bdf030139e813572 to your computer and use it in GitHub Desktop.
JavaFilterOperation
public class JavaFilterOperation {
private List<String> items;
@FunctionalInterface
interface FilterOperation {
Boolean filter(String element);
}
private List<String> filterBy(FilterOperation fn) {
return items.stream()
.filter(fn::filter) // applying the function
.collect(Collectors.toList());
}
public void doFilter() {
filterBy((element) -> {
return element.length() > 0;
// calling the function with an actual lambda
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment