Created
September 11, 2017 16:36
-
-
Save adam-arold/9276ed18fec50fa4bdf030139e813572 to your computer and use it in GitHub Desktop.
JavaFilterOperation
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
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