Skip to content

Instantly share code, notes, and snippets.

@benweidig
Created April 11, 2024 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benweidig/06e71b299c5707d4f04a75c0323b1b12 to your computer and use it in GitHub Desktop.
Save benweidig/06e71b299c5707d4f04a75c0323b1b12 to your computer and use it in GitHub Desktop.
Figure 6-4: Flow of Book elements through the Stream pipeline
Type of Return
Operation Stream Operations Type
─────────────────────────────────────────────────────────────────────────────────────────────────────
┌──────────────────────────────────────────────────────────────┐
Source │ Book Book Book Book Book Book Book Book Book │ List<Book>
└─────────────────────────────┬────────────────────────────────┘
v
┌──────────────────────────────────────────────────────────────┐
Creation │ .stream() │ Stream<Book>
└─┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬────┘
│B1 │B2 │B3 │B4 │B5 │B6 │B7 │B8 │B9
v v v v v v v v v
┌──────────────────────────────────────────────────────────────┐
Intermediate │ .filter(book -> book.year() == 1999) │ Stream<Book>
└─┬─────────────┬─────────────┬──────┬─────────────┬──────┬────┘
│B1 │B3 │B5 │B6 │B8 │B9
v v v v v v
┌──────────────────────────────────────────────────────────────┐
Intermediate │ .filter(book -> book.genre() == Genre.SCIENCE_FICTION) │ Stream<Book>
└───────────────┬────────────────────┬─────────────┬──────┬────┘
│B3 │B6 │B8 │B9
v v v v
┌──────────────────────────────────────────────────────────────┐
Intermediate │ .map(Book::title) │ Stream<String>
└───────────────┬────────────────────┬─────────────┬──────┬────┘
│B3 │B6 │B8 │B9
v v v v
┌──────────────────────────────────────────────────────────────┐
Intermediate │ .sorted() │ Stream<String>
(stateful) └────────────────────┬──────┬──────┬──────┬────────────────────┘
│B8 │B3 │B6 │B9
v v v v
┌──────────────────────────────────────────────────────────────┐
Intermediate │ .limit(3) │ Stream<String>
(stateful) └──────────────────────┬──────┬──────┬─────────────────────────┘
│B8 │B3 │B6
v v v
┌──────────────────────────────────────────────────────────────┐
Terminal │ .collect(Collectors.toList()) │ List<String>
└──────────────────────────────────────────────────────────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment