Created
April 11, 2024 05:28
-
-
Save benweidig/06e71b299c5707d4f04a75c0323b1b12 to your computer and use it in GitHub Desktop.
Figure 6-4: Flow of Book elements through the Stream pipeline
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
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