Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20250331
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
20250331
Commits
b10b6b87
Commit
b10b6b87
authored
Apr 07, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mapMulti i flatMap - komentarze
parent
1b5cf06c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
C12_FlatMap.java
...a/gotowe/p31_streamy/c_przeglad_operacji/C12_FlatMap.java
+10
-2
C13_MultiMap.java
.../gotowe/p31_streamy/c_przeglad_operacji/C13_MultiMap.java
+4
-0
No files found.
src/main/java/gotowe/p31_streamy/c_przeglad_operacji/C12_FlatMap.java
View file @
b10b6b87
...
@@ -37,18 +37,26 @@ public class C12_FlatMap {
...
@@ -37,18 +37,26 @@ public class C12_FlatMap {
System
.
out
.
println
();
System
.
out
.
println
();
System
.
out
.
println
();
System
.
out
.
println
();
// W zwykłym map wynikowy strumień zawiera tyle samo elementów, co wejściowy.
// Jeśli funkcja mapuje wartości na kolekcje - wynikiem jest strumień kolekcji.
// Jeśli funkcja mapuje wartości na strumienie - wynikiem jest strumień strumieni.
System
.
out
.
println
(
"Zwykłe mapowanie:"
);
System
.
out
.
println
(
"Zwykłe mapowanie:"
);
Stream
.
of
(
1
,
3
,
0
,
5
)
Stream
.
of
(
1
,
3
,
0
,
5
)
.
map
(
C12_FlatMap:
:
generuj
)
.
map
(
C12_FlatMap:
:
generuj
)
.
forEach
(
x
->
System
.
out
.
print
(
x
+
" | "
));
.
forEach
(
x
->
System
.
out
.
print
(
x
+
" | "
));
System
.
out
.
println
();
System
.
out
.
println
();
Stream
.
of
(
1
,
3
,
0
,
5
)
Stream
.
of
(
1
,
3
,
0
,
5
)
.
map
(
x
->
C12_FlatMap
.
generuj
(
x
).
stream
())
.
map
(
x
->
C12_FlatMap
.
generuj
(
x
).
stream
())
.
forEach
(
x
->
System
.
out
.
print
(
x
+
" | "
));
.
forEach
(
x
->
System
.
out
.
print
(
x
+
" | "
));
System
.
out
.
println
();
System
.
out
.
println
();
System
.
out
.
println
();
System
.
out
.
println
();
// We flatMap funkcja powinna mapować wartość na strumień, a wynikiem jest konkatenacja wynikowych strumieni.
// Daje to możliwość mapowania pojedynczego elementu wejściowego na dowolną liczbę elementóœ wynikowych:
// zero (!), jeden, dowolną skończoną liczbę, a nawet nieskońćzoność.
// Funkcja mapuje wartości na strumienie - wynikiem jest strumień wartości.
System
.
out
.
println
(
"Płaskie mapowanie:"
);
System
.
out
.
println
(
"Płaskie mapowanie:"
);
Stream
.
of
(
1
,
3
,
5
)
Stream
.
of
(
1
,
3
,
5
)
.
flatMap
(
x
->
C12_FlatMap
.
generuj
(
x
).
stream
())
.
flatMap
(
x
->
C12_FlatMap
.
generuj
(
x
).
stream
())
...
@@ -67,5 +75,5 @@ public class C12_FlatMap {
...
@@ -67,5 +75,5 @@ public class C12_FlatMap {
.
sum
();
.
sum
();
System
.
out
.
println
(
suma
);
System
.
out
.
println
(
suma
);
}
}
}
}
src/main/java/gotowe/p31_streamy/c_przeglad_operacji/C13_MultiMap.java
View file @
b10b6b87
...
@@ -13,6 +13,10 @@ public class C13_MultiMap {
...
@@ -13,6 +13,10 @@ public class C13_MultiMap {
.
forEach
(
x
->
System
.
out
.
print
(
x
+
" | "
));
.
forEach
(
x
->
System
.
out
.
print
(
x
+
" | "
));
System
.
out
.
println
();
System
.
out
.
println
();
// W mapMulti funkcja powinna przyjąć element strumienia wejściowego i wykonać odpowiednią ilość akcji
// na przekazanym do niej obiekcie Consumer.
// Wynikiem jest strumień składający się z tych wartości, które za pomocą accept zostały dostarczone do Consumera.
// Istotne jest, że wynikowy strumień może zawierać mniej lub więcej elementów, niż wejściowy (podobnie jak we flatMap).
System
.
out
.
println
(
"mapMulti"
);
System
.
out
.
println
(
"mapMulti"
);
Stream
.
of
(
1
,
3
,
0
,
5
)
Stream
.
of
(
1
,
3
,
0
,
5
)
.
mapMulti
((
n
,
c
)
->
{
.
mapMulti
((
n
,
c
)
->
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment