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
How I Lazy and You Can Ruby 2
Search
Stephen Caudill
March 12, 2014
Programming
91
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
How I Lazy and You Can Ruby 2
Lightning talk on Ruby's Enmuerator::Lazy
Stephen Caudill
March 12, 2014
More Decks by Stephen Caudill
See All by Stephen Caudill
iOS BDD Beatdown
voxdolo
7
5.6k
Other Decks in Programming
See All in Programming
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
0
1.8k
FreeBSDでZabbixを動かす
kenkino
0
320
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
310
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
660
Verilogで学ぶCPU自作入門.pdf
uyuki234
8
3.2k
新卒PdEのリアル
ryu1013
1
520
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.5k
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
500
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
130
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
150
一人だけ、Kiroが静止する日
hideg
0
130
AWSに止められる覚悟してますか?
morizo_1984
1
300
Featured
See All Featured
Utilizing Notion as your number one productivity tool
mfonobong
4
600
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
490
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
500
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Amusing Abliteration
ianozsvald
1
310
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
610
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
530
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.9k
Transcript
Stephen Caudill @voxdolo
How I Lazy And You Can Ruby 2
Enumerator::Lazy
lazy evaluation In computer programming, lazy evaluation is the technique
of delaying an evaluation of any expression until a value is actually being used and also avoid repeated evaluations.
eager evaluation In computer programming, eager evaluation or greedy evaluation
is the evaluation strategy used by most traditional programming languages. In eager evaluation, an expression is evaluated as soon as it is bound to a variable.
eager evaluation (1..Float::INFINITY).map do |i| i ** 2 end
IRB::Abort: abort then interrupt!
(1..Float::INFINITY).lazy.map do |i| i ** 2 end lazy evaluation
#<Enumerator::Lazy:#<Enumerator::Lazy: 1..Infinity>:map>
Enumerator::Lazy#force “When it absolutely, positively has to be there [right
now]”
(1..Float::INFINITY).lazy.map do |i| i ** 2 end.force
IRB::Abort: abort then interrupt!
(1..Float::INFINITY).lazy.map do |i| i ** 2 end.take(10).force
(1..Float::INFINITY).lazy.map do |i| i ** 2 end.first(10)
[1,4,9,16,25,36,49,64,81,100]
Now wait just a cotton-picking minute
Why be lazy?
fibonacci = Enumerator.new do |enum| yielder = ->(n){ enum.yield n
} yielder.call(a=0) yielder.call(b=1) loop do a, b = b, a + b yielder.call(b) end end Combinatorics .lazy
fibonacci.first(10) ! => [0,1,1,2,3,5,8,13,21,34]
(1..Float::INFINITY).lazy.select do |x| x ** 2 % 5 == 0
end.take(10).reduce(:+) ! => 275
Stephen Caudill @voxdolo
None