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
570
fs2で始める関数型ストリーミング処理入門
関数型ストリーミング処理に出会ったときにこわくない程度の感覚を掴むために
Kazunari Mori
October 08, 2016
Tweet
Share
Other Decks in Programming
See All in Programming
見た目から始める生産性向上
ikumatadokoro
10
1.5k
サイコロで理解する統計的仮説検定の考え方
tatamiya
4
1.1k
Apache Hive 4 on Treasure Data
ryukobayashi
1
440
Elm Form Validation
bkuhlmann
0
520
冗長なエラーログを削減し、スタックトレースを手に入れる / Reducing Verbose Error Logs and Obtaining Stack Traces
upamune
0
1.1k
CREってこういうこと? 体験入社 - 提案資料 - / what-is-cre-trial-employment
shinden
1
560
Hanami and htmx
bkuhlmann
0
230
障害対応を起点としたもっといい開発と運用のサイクル作りのためにできること / Hatena Enginner Seminar #29
polamjag
0
410
Direct Style Effect Systems The Print[A] ExampleA Comprehension Aid
philipschwarz
PRO
0
170
WebGLで始める コンピュータグラフィックス入門
heller77
0
330
PostmanでAPIの動作確認が楽になった話
h455h1
0
190
敵対的ポイフル
futabato
0
140
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
13
2.4k
Agile that works and the tools we love
rasmusluckow
325
20k
Mobile First: as difficult as doing things right
swwweet
217
8.6k
What's new in Ruby 2.0
geeforr
337
31k
BBQ
matthewcrist
80
8.8k
Bash Introduction
62gerente
605
210k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
The Illustrated Children's Guide to Kubernetes
chrisshort
32
47k
Building Flexible Design Systems
yeseniaperezcruz
320
37k
Pencils Down: Stop Designing & Start Developing
hursman
117
11k
Debugging Ruby Performance
tmm1
70
11k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
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