Created
May 6, 2013 06:31
-
-
Save knjname/5523635 to your computer and use it in GitHub Desktop.
Add Debugging Pipe
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
| import java.util.Arrays; | |
| import java.util.function.Function; | |
| /** | |
| * Created with IntelliJ IDEA. | |
| * User: owner | |
| * Date: 13/05/06 | |
| * Time: 14:41 | |
| * To change this template use File | Settings | File Templates. | |
| */ | |
| public class StreamExample { | |
| public static void main(String... args){ | |
| Arrays.asList("1", "Foo", "2", "Bar", "3") | |
| .stream() | |
| .map(debug("Before filter: ")) | |
| .filter(str -> str.matches("\\d")) | |
| .map(debug("After filter: ")) | |
| .forEach(System.out::println); | |
| } | |
| public static <T> Function<T, T> debug(String debugStr){ | |
| return (T t) -> { | |
| System.out.println(debugStr + t); | |
| return t; | |
| }; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
Before filter: 1
After filter: 1
1
Before filter: Foo
Before filter: 2
After filter: 2
2
Before filter: Bar
Before filter: 3
After filter: 3
3