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
680
fs2で始める関数型ストリーミング処理入門
関数型ストリーミング処理に出会ったときにこわくない程度の感覚を掴むために
Kazunari Mori
October 08, 2016
Tweet
Share
Other Decks in Programming
See All in Programming
flutter_kaigi_mini_4.pdf
nobu74658
0
150
note の Elasticsearch 更新系を支える技術
tchov
9
3.6k
Beyond_the_Prompt__Evaluating__Testing__and_Securing_LLM_Applications.pdf
meteatamel
0
110
読書シェア会 vol.4 『ダイナミックリチーミング 第2版』
kotaro666
0
110
LRパーサーはいいぞ
ydah
7
1.4k
ドメイン駆動設計とXPで支える子どもの未来 / Domain-Driven Design and XP Supporting Children's Future
nrslib
0
290
プロダクトエンジニアのしごと 〜 受託 × 高難度を乗り越えるOptium開発 〜
algoartis
0
220
2025-04-25 GitHub Copilot Agent ライブデモ(スクリプト)
goataka
0
110
The New Developer Workflow: How AI Transforms Ideas into Code
danielsogl
0
130
Road to Ruby for A Linguistics Nerd
hayat01sh1da
PRO
0
300
20250429 - CNTUG Meetup #67 / DevOps Taiwan Meetup #69 - Deep Dive into Tetragon: Building Runtime Security and Observability with eBPF
tico88612
0
180
Embracing Ruby magic
vinistock
2
250
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Into the Great Unknown - MozCon
thekraken
38
1.8k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
VelocityConf: Rendering Performance Case Studies
addyosmani
329
24k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Rails Girls Zürich Keynote
gr2m
94
13k
Stop Working from a Prison Cell
hatefulcrawdad
268
20k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.4k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
137
33k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.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