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
How I Lazy and You Can Ruby 2
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
typoなんかねぇよ
raspython3
0
550
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
280
Go 1.27 における memory allocation の高速化
andpad
0
320
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
2
440
PyConJP2026_wat_Python × Signal Processing: How to Draw Pictures with Sound Using Spectrogram Art
wat
0
400
VibeCodingからAgenticWorkflowへ
starfish719
0
870
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
19k
不幸な GC
chencmd
0
740
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
260
30年振りにコンパイラの定数整数除算を改善した
herumi
9
4.2k
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
210
ALB ログから Trace を気合で繋げる技術
fohte
6
630
Featured
See All Featured
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.8k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
Designing for Timeless Needs
cassininazir
1
450
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
260
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
580
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Discover your Explorer Soul
emna__ayadi
2
1.3k
How to Ace a Technical Interview
jacobian
281
24k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
340
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