Skip to content

Instantly share code, notes, and snippets.

@jmaciasluque
Last active October 6, 2015 15:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jmaciasluque/4d5b5383d1e2ba36331b to your computer and use it in GitHub Desktop.
package me.juanmacias;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
public class Gotcha1NoTerminalOperation {
public static void main(String[] args) {
List<String> eulogy = Arrays.asList("yo", "quiero", "ser", "llorando", "el", "hortelano");
Stream<String> eulogyStream = eulogy.stream().filter(word -> {
System.out.println("while filtering (intermediate operation)... " + word);
return word.contains("a");
}).map(word -> {
System.out.println("while uppercasing (intermediate operation)... " + word);
return word.toUpperCase();
});
// eulogyStream.peek(word -> System.out.println("peeking before counting (terminal operation)... " + word)).count();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment