Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
5分で分かるかもしれないjava8 Stream API
Search
Kazuhiro Serizawa
November 26, 2015
Programming
1
2.2k
5分で分かるかもしれないjava8 Stream API
Kazuhiro Serizawa
November 26, 2015
Tweet
Share
More Decks by Kazuhiro Serizawa
See All by Kazuhiro Serizawa
Accelerating Machine Learning I/O by Overlapping Data Staging and Mini-batch Generations
serihiro
1
280
hpc170_slide.pdf
serihiro
0
41
画像解像度別ImageNetの100 iterationの合計処理時間比較
serihiro
0
89
深層ニューラルネットワークにおける訓練高速化のための自動最適化
serihiro
0
36
Introduction to Parallel Computing 2.2
serihiro
0
51
My summer internship result at Treasure Data 2018 #td_intern
serihiro
0
2k
startupでもrails使うなら これだけはやっとけ的 tips集
serihiro
19
10k
つらくないコードレビューの運用
serihiro
43
20k
Other Decks in Programming
See All in Programming
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
Quine, Polyglot, 良いコード
qnighy
4
640
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.7k
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
170
Arm移行タイムアタック
qnighy
0
320
cmp.Or に感動した
otakakot
2
140
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
RubyLSPのマルチバイト文字対応
notfounds
0
120
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
910
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
65
4.4k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Bash Introduction
62gerente
608
210k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
YesSQL, Process and Tooling at Scale
rocio
169
14k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Being A Developer After 40
akosma
86
590k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Transcript
5Ͱ͔Δ͔͠Εͳ͍ java8 Stream API
java8ʹ͍ͭͯ • 20143݄18ʹOracle͔Βެ։ • “ੈքҰͷ։ൃϓϥοτϑΥʔϜͷըظతͳϦϦʔ ε” ※OracleେຊӦൃද • ϥϜμࣜɺStreamAPIɺDate and
Time APIͳͲͷ ৽ػೳͷಋೖͰjavaքʹֵ໋͕ʂ ʢͱࢥ͚ͬͨͲͦ͜·ͰΓ্͕Βͳ͔ͬͨʣ
ࠓ͔̑͠ͳ͍ͷͰ • Stream APIʹ͍ͭͯ֓ཁΛ͠·͢ • ʮjavaগ͠ϚγʹͳͬͨΑ͏ͩͳʯ ͱ͍͏ͷΛײ͡औͬͯΒ͑Ε͍Ͱ͢
Stream APIͱʁ • ྻɺϦετͳͲͷෳͷσʔλʹ͓͚Δू ૢ࡞ͷαϙʔτΛߦ͏API • ฒߦॲཧΒͷϕϯϦػೳΛఏڙͯ͘͠ΕΔ UtilͰͳ͘Interface͚ͩΛఏڙ͢Δ
Stream APIͱʁ • ཁ͢ΔʹRubyͰݴ͏ͱ͜Ζͷ • Enumerable#each • Enumerable#select • Enumerable#map
• ͜ΕΒͷॲཧΛʮܾ·ͬͨखॱͰ࣮ߦ͢ΔʯAPI • Stream API ≠࣮ɻInterfaceͷΈΛఆ͍ٛͯ͠Δɻ
StreamΛΘͳ͍߹ͷྫ List<Integer> list = Arrays.asList(1,2,3); Integer result = 0; for
(Integer i : list) { result += i * i; } System.out.println(result); //14
ͳ͓ruby result = [1,2,3] .map{ |i| i*i } .inject{ |a,b|
a + b } puts result #=> 14
StreamΛ͏߹ͷྫ List<Integer> list = Arrays.asList(1,2,3); Integer result = list.stream() .map(x
-> x * x) .reduce((a, b) -> a + b) .get(); System.out.println(result); //14
Stream APIΛ༻͍࣮ͨ "SSBZ -JTUͳͲͷ %BUBTPVSDF TUSFBN࡞ தؒૢ࡞ ϑΟϧλϦϯάɾͷૢ࡞ͳͲ ऴૢ࡞ ूૢ࡞ɾผΫϥεͷมɾ
ஞ࣍ॲཧͳͲ ॲཧ͞Εͨ݁Ռ list.stream() .map(x -> x * x) .reduce((a, b) -> a + b) .get();
ඪ४ϥΠϒϥϦ with Stream Stream<String> lines = Files.lines(path) lines.filter(line -> line.startsWith(“a”))
.map(s -> s.toUpperCase) .forEach(s -> System.out.println(s)); // “AMAZON” // “ATOM”
StreamʹΑͬͯԿ͕͏Ε͍͔͠ • σʔλϦιʔεૢ࡞ͷ࣮ͷ؆ུԽ • ϥϜμࣜͱΈ߹ΘͤΔ͜ͱͰ ؔܕͬΆ͍syntaxʹ • σʔλϦιʔεʹର͢Δฒߦॲཧɾࢄॲཧ Λstream()ϝιουʹӅṭԽ࣮ͯ͠Ͱ͖Δ
Collection frameworkͩͱ ϚϧνεϨουͰฒߦॲཧ͢ΔstreamΛ࡞ΕΔ List<Integer> list = Arrays.asList(1,2,3); Integer result =
list.parallelStream() .map(x -> x * x) .reduce((a, b) -> a + b) .get(); System.out.println(result); //14
༨ஊɿ Apache SparkΛͬͨࢄॲཧ࣮ input. flatMap(line -> Arrays.asList(line.split("\\s+"))) .mapToPair(word -> new
Tuple2(word, 1)) .reduceByKey((x, y) -> (Integer) x + (Integer) y) .sortByKey() .collect();
Stream APIͷ·ͱΊ • ීஈྑ͘͏Collection Frameworkͷॲཧ͕ γϯϓϧʹ࣮Ͱ͖ΔΑ͏ʹͳΔ • rubyʹ༏͍͠ • ࢄɾฒߦॲཧΛӅṭԽ࣮ͯ͠Ͱ͖ͦ͏ͳ
ઃܭํΛ͍ࣔͯ͠Δ