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
fs2で始める関数型ストリーミング処理入門
Search
Kazunari Mori
October 08, 2016
Programming
0
710
fs2で始める関数型ストリーミング処理入門
関数型ストリーミング処理に出会ったときにこわくない程度の感覚を掴むために
Kazunari Mori
October 08, 2016
Tweet
Share
Other Decks in Programming
See All in Programming
エンジニアインターン「Treasure」とHonoの2年、そして未来へ / Our Journey with Hono Two Years at Treasure and Beyond
carta_engineering
0
390
登壇は dynamic! な営みである / speech is dynamic
da1chi
0
350
contribution to astral-sh/uv
shunsock
0
440
XP, Testing and ninja testing ZOZ5
m_seki
3
790
Leading Effective Engineering Teams in the AI Era
addyosmani
7
550
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
520
チームの境界をブチ抜いていけ
tokai235
0
210
テーブル定義書の構造化抽出して、生成AIでDWH分析を試してみた / devio2025tokyo
kasacchiful
0
250
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
530
ALL CODE BASE ARE BELONG TO STUDY
uzulla
26
6.6k
What's new in Spring Modulith?
olivergierke
1
160
iOSでSVG画像を扱う
kishikawakatsumi
0
150
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.1k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3k
How to Think Like a Performance Engineer
csswizardry
27
2.1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
30
2.9k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.7k
Building Adaptive Systems
keathley
44
2.8k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
How to train your dragon (web standard)
notwaldorf
97
6.3k
Transcript
None
None
None
None
None
• 昨今のバズワード「ビッグデータ」とも戦える!!
• データは次々流れてくる • 自分のところにデータが来たら、自分の やるべき処理を実行 • 処理済みデータは次の担当の元へ • def work(p:
Pet): Pet = if (p.fallen) raise(p) else p • 1データを処理する関数を作るだけ! • (12本ためて箱に詰める、なども。)
None
fs2 Stream class Stream F _ O • O •
F _ • fs2 util Catchable F fs2 Task Catchable F Task F O
• Stream ファイル DB Web ファイル DB Web fs2.Stream
• Stream List A def O2 O O2 Stream F
O2 def O2 O Stream F O2 Stream F O2 def F2 O2 Stream F O Stream F2 O2 Stream F2 O2 Stream Stream Task java sql Connection • Stream Stream Stream
None
Stream F Byte Stream F String • ascii文字しか無いならば、すべて1文字1バイト。 • でも、半角カタカナはutf-8では3バイト・・・
• こういうときにChunkという概念が便利。 trait Chunk[+A] • ChunkはA型のデータの幾つかの塊というイメージ
• Stream O2 Chunk Chunk O2 • Chunk A Vector
A Vector A Chunk Chunk A • 以下の点には注意が必要 • Chunkにはいくつデータが入っているのかわからない。 • どこかChunkに入ったデータは、次のChunkには入らない。 • Chunkのうち使いきれなかった分をキャッシュして、 次のChunkの先頭にくっつける処理が必要になる事が多い。 • Pipe型、Handle型やPull型を参照。 • fs2.textにutf8Decodeなどがあるので、ソースを読めば・・・。
Stream def f[F[_], A]: fs2.Pipe[F, A, (A, A)] = {
s => for { a <- s.take(1) b <- s.tail.take(1) c <- f(s.tail).cons1((a, b)) } yield c }
None
• 例えば、ソート処理。 データの中で最小の値をはじめに持ってくる。 データをすべて見ないと最小の値がわからない。 ⇒ すべてのデータを見るまで値をキャッシュする? • 無限に終わりが来ないストリームも簡単に作成可能。
• ランダムアクセスが必要な処理全般が不可能。 一度使用した値は意図的にキャッシュしない限りは残らない。 • Lengthを取得するだけですべての値の走査が必須
None