Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Why foldRight is beautiful
Search
Jun Tomioka
July 18, 2018
Technology
300
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Why foldRight is beautiful
Explains why "foldRight" is beautiful.
Jun Tomioka
July 18, 2018
More Decks by Jun Tomioka
See All by Jun Tomioka
Dotty で軽量な DI ライブラリをかいてみた
jooohn
1
390
ソフトウェアエンジニアとしてモナドを完全に理解する / make-perfect-sense-of-monad
jooohn
14
8.1k
ScalaのコンパイラにFizzBuzzを解いてもらう(Dottyもあるよ)
jooohn
1
1.2k
Write stack safe non-tailrec recursive functions
jooohn
4
1k
Introduction to Clean Architecture
jooohn
1
620
人類には早すぎる、謎の計算ロジックに立ち向かう / Strugle with the most complicated logic ever
jooohn
1
1.8k
Work at M3 USA
jooohn
0
1.5k
クラウド電子カルテを支えるテクノロジーの光と闇
jooohn
0
1.4k
怖くないCats
jooohn
0
940
Other Decks in Technology
See All in Technology
2026-09-26 Platform Engineering Kaigi 2026 インフラとアプリの境界線と委譲の設計 / Drawing the Infra and App Line
masasuzu
0
600
AIに攻撃される前に、AIに攻撃させる
tsuchikazu
0
120
AWS FinOps Agent 結局何が得意なの?
siromi
0
230
OpenSharing について熱く語る〜AI アセットの共有について〜
kameitomohiro
0
130
SDDの運用にめげずに向き合った話
sansantech
PRO
0
110
生成AIと進める探索的データ分析(2026.10.03 第122回Tokyo.R勉強会)
tatamiya
2
1.3k
AgentCoreで実践するハーネスエンジニアリング
yakumo
1
240
FinTech 1-2 : Overview of FinTech
ks91
PRO
0
130
組み立てて楽しむ AWS Blocks 入門
kmiya84377
0
150
KanaAI
shreyas1009
0
140
Meet AgentCore Identity Consent Portal
hironobuiga
3
170
大阪オフィスに Unitree Go2 がやってきたので Physical AI やってみた
dafujii
0
250
Featured
See All Featured
Utilizing Notion as your number one productivity tool
mfonobong
4
610
Optimising Largest Contentful Paint
csswizardry
37
4k
Into the Great Unknown - MozCon
thekraken
41
2.7k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
Evolving SEO for Evolving Search Engines
ryanjones
0
300
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Test your architecture with Archunit
thirion
2
2.4k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
510
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Color Theory Basics | Prateek | Gurzu
gurzu
1
480
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Transcript
Why foldRight is beautiful Jun Tomioka (M3, inc.)
M3, Inc. Jun Tomioka Twitter: @jooohn1234 Github: jooohn Love: Our
very first baby Had great paternity leave!
None
foldLeft / foldRight
trait List[+A]
foldLeft[B](z: B)(op: (B, A) => B): B A A A
A A B A A A A B B OP ...
foldRight[B](z: B)(op: (A, B) => B): B A A A
A A B A A A A B B OP ...
So what’s the difference between them?
Suppose you define your own Linked List
foldLeft would be like this
foldRight would be like this
This naive foldRight can cause stack overflow
If so, why can foldRight be beautiful?
Let’s implement “map” with foldLeft
A A A A A List[B] A A A A
OP ... List[B] List[B]
Let’s implement “map” with foldLeft
foldRight
Let’s implement “map” with foldRight
A A A A A List[B] A A A A
List[B] List[B] OP ...
Why is it that natural to write “map” with foldRight?
Immutable recursive data structure
Bigger part holds smaller part
We must create them from smaller part to bigger part
This is the folding order of foldRight
foldRight folds items by its creation order
Why foldRight is beautiful • Immutable recursive data structure is
built from smaller part to bigger part • In this sense, foldRight folds items from smaller part to bigger part rather than from right to left ◦ Is quite natural to treat immutable recursive data structure
Thanks!