Created
August 9, 2017 00:51
-
-
Save felipebelluco/3eee9070eba7df63a3552f45a171145e to your computer and use it in GitHub Desktop.
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.*; | |
import static br.com.felipebelluco.javaplayground.PredicateUtil.negate; | |
public class Main { | |
public static void main(String[] args) { | |
List<String> list = Arrays.asList("foo", "", "bar"); | |
// Instead of this... | |
list.stream().filter(name -> !name.isEmpty()).forEach(System.out::println); | |
// Use this | |
list.stream().filter(negate(String::isEmpty)).forEach(System.out::println); | |
} | |
} |
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.function.Predicate; | |
public class PredicateUtil { | |
static <T> Predicate<T> negate(Predicate<T> predicate) { | |
return predicate.negate(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment