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
730
0
Share
fs2で始める関数型ストリーミング処理入門
関数型ストリーミング処理に出会ったときにこわくない程度の感覚を掴むために
Kazunari Mori
October 08, 2016
Other Decks in Programming
See All in Programming
AI Agent と正しく分析するための環境作り
yoshyum
2
550
Kubernetesを使わない環境にもCloud Nativeなデプロイを実現する / Enabling Cloud Native deployments without the complexity of Kubernetes
linyows
3
430
20260514_its_the_context_window_stupid.pdf
heita
0
1.1k
TypeScriptだけでAIエージェントを作る フロント・エージェント・インフラのフルスタック実践
har1101
5
740
Import assertionsが消えた日~ECMAScriptの仕様はどう決まり、なぜ覆るのか~
bicstone
2
190
自動レビューエンジンの実装と運用 ~レビューのない世界へ~
kurukuru1999
1
120
AI時代だからこそ「Bloc」を採用する価値があるのかもしれない
takuroabe
0
200
Surviving Black Friday: 329 billion requests with Falcon!
ioquatix
0
3.2k
密結合なバックエンドから TypeScript のコードを生成する
kemuridama
1
260
[BalkanRuby 2026] Drop your app/services!
palkan
3
600
Sans tests, vos agents ne sont pas fiables
nabondance
0
140
cloudnative conference 2026 flyle
azihsoyn
1
200
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
97
6.6k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Claude Code のすすめ
schroneko
67
220k
The untapped power of vector embeddings
frankvandijk
2
1.7k
What does AI have to do with Human Rights?
axbom
PRO
1
2.1k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
170
The Spectacular Lies of Maps
axbom
PRO
1
750
Marketing to machines
jonoalderson
1
5.3k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.7k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
180
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Paper Plane (Part 1)
katiecoart
PRO
0
7.7k
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