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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Kazunari Mori
October 08, 2016
Programming
730
0
Share
fs2で始める関数型ストリーミング処理入門
関数型ストリーミング処理に出会ったときにこわくない程度の感覚を掴むために
Kazunari Mori
October 08, 2016
Other Decks in Programming
See All in Programming
AWSコミュニティ活動は顧客のクラウド推進に効くのか / Do AWS community activities help customers adopt the cloud?
seike460
PRO
0
140
Liberating Ruby's Parser from Lexer Hacks
ydah
2
1.4k
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
4
380
JAWS-UG横浜 #100 祝・第100回スペシャルAWS は VPC レスの時代へ
maroon1st
0
150
GNU Makeの使い方 / How to use GNU Make
kaityo256
PRO
16
5.6k
今こそ押さえておきたい アマゾンウェブサービス(AWS)の データベースの基礎 おもクラ #6版
satoshi256kbyte
1
250
運転動画を検索可能にする〜Cosmos-Embed1とDatabricks Vector Searchで〜/cosmos-embed1-databricks-vector-search
studio_graph
0
320
アクセシビリティ試験の"その後"を仕組み化する
yuuumiravy
0
150
The Less-Told Story of Socket Timeouts
coe401_
3
420
How Swift's Type System Guides AI Agents
koher
0
270
ローカルで稼働するAI エージェントを超えて / beyond-local-ai-agents
gawa
3
280
Back to the roots of date
jinroq
0
250
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
247
13k
The Limits of Empathy - UXLibs8
cassininazir
1
310
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
340
AI: The stuff that nobody shows you
jnunemaker
PRO
6
580
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.4k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
Marketing to machines
jonoalderson
1
5.2k
Paper Plane (Part 1)
katiecoart
PRO
0
6.7k
Technical Leadership for Architectural Decision Making
baasie
3
330
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
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