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
【Go言語】クロージャ
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Tomoki Ota
October 04, 2024
Programming
340
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
【Go言語】クロージャ
一部Rustのとこも出てきます
Tomoki Ota
October 04, 2024
More Decks by Tomoki Ota
See All by Tomoki Ota
アーキテクチャの価値
tomo1227
0
130
アーキテクチャとビジネスロジック
tomo1227
0
130
【Go言語】テスト
tomo1227
0
94
【Go言語】イテレータ
tomo1227
0
120
【Go言語】エラーハンドリング
tomo1227
0
96
AIに淘汰されないようにするには?
tomo1227
0
97
【Go言語】range
tomo1227
0
110
【Go言語】break
tomo1227
0
98
【Go言語】反復処理
tomo1227
0
76
Other Decks in Programming
See All in Programming
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
190
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
290
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
160
Build-to-own AI: Agentic Development for Humans
inesmontani
PRO
0
110
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
360
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.4k
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
2
1.2k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
440
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
480
数百円から始めるRuby電子工作
tarosay
0
110
使いながら育てる Claude Code — 開発フローの1コマンド化 × 繰り返し指摘の自動仕組み化
shiki_kakaku
0
1.3k
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
190
Featured
See All Featured
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
From π to Pie charts
rasagy
0
240
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
750
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
190
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
370
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
250
Transcript
Tomoki Ota ʲGoݴޠʳΫϩʔδϟ࣮ફฤ
Ϋϩʔδϟ࣮ફฤ GoͷΠςϨʔλ ΞδΣϯμ 2
Ϋϩʔδϟͱʁ
Ϋϩʔδϟͱʁ 4 •ڥΛΩϟϓνϟͰ͖Δແ໊ؔ
ϝϦοτ 5 • άϩʔόϧมΛ༻͍Δඞཁ͕ͳ͘ͳΔ • ؔͷείʔϓΛ੍ݶͰ͖Δ
Ϋϩʔδϟͷ߹ 6
ؔͷ߹ 7
Ϋϩʔδϟ࣮ફฤ
9 ࠨͷίʔυͷ ʁ
10 1 ॏ͍ॲཧcalcTrainingRepsͷݺͼग़͠෦͕ ෳՕॴ͋ΔͷͰɺมߋ͕໘
11 2 ॏ͍ॲཧΛෳճ࣮ߦ͠ͳ͚ΕͳΒͳ͍ Մೳੑ͕͋Δɻ
12 ؔͰϦϑΝΫλ
13 ؔͰϦϑΝΫλ ͜Εͩͱ2͕ղܾ͍ͯ͠ͳ͍ɻ ͞ΒʹɺrepsΛ༻͠ͳ͍ͱ͖ ॏ͍ॲཧΛݺͼͩ͞ΕΔͱ͍͏৽ͨͳ͕ Ճ͞ΕΔɻ
14 ΫϩʔδϟͰϦϑΝΫλ ΫϩʔδϟΛ͏͜ͱͰɺreps͕ඞཁͳ͚࣌ͩ ίʔυΛ࣮ߦ͢Δ
ߴ֊ؔ
ߴ֊ؔͱʁ 16 ؔΛҾʹͱͬͨΓɺؔΛΓͱͨ͠Γ͢Δؔ
ϝϦοτ 17 ϓϩάϥϜͷॊೈੑ ίʔυͷ؆ܿੑ ࠶ར༻ੑ ϝϯςφϯεੑ
Goʹ͓͚Δߴ֊ؔ 18
ίʔϧόοΫ 19
ΧϦʔԽ
ΧϦʔԽͱʁ 21 f(a, b, c)Λf(a)(b)(c)ͷΑ͏ʹҾΛ1ͭʹ͢Δ
22 ΧϦʔԽ͍ͯ͠ͳ͍ྫ ΧϦʔԽΛͬͯϦϑΝΫλͨ͠ྫ
෦ద༻
෦ద༻ 24 ΧϦʔԽ͞ΕͨؔɺҙͷҾΛݻఆͨ͠ผͷؔΛ࡞͢Δ͜ͱ͕Ͱ͖Δ
25 ෦ద༻
CPS
CPSͱʁ 27 continuation-passing styleɺܧଓ͠ελΠϧͱ͍͏ɻ ؔͷୈ1Ҿʹɺޙʹଓ͘ॲཧ(ܭଌ)Λ͢ϓϩάϥϛϯάελΠϧ CJavaͰɺޙʹଓ͘ॲཧΛηϛίϩϯͱվߦͷޙʹଓࣜ͘
CPSͷ݅ 28 •First-class Function(ୈҰڃؔ) •Tail-Call optimization(ඌݺͼग़͠࠷దԽ) GoͷίϯύΠϥରԠ͍ͯ͠ͳ͍
CPSͷ݅ 29
CPSͷྫ 30
CPSͷ݅ 31
࠶ؼͱඌ࠶ؼ 32
࠶ؼͱඌ࠶ؼ 33
࠶ؼͱඌ࠶ؼ 34
δΣωϨʔλ
δΣωϨʔλͱ 36 ΠςϨʔλΛ؆୯ʹ࡞Δ͜ͱ͕Ͱ͖ΔɻΠςϨʔλΛฦؔ͢ δΣωϨʔλؔͱ͍͏ɻ ·ͨɺδΣωϨʔλؔͰ࡞͞ΕͨΠςϨʔλͷ͜ͱΛ δΣωϨʔλͱݺͿ͜ͱ͋Δɻ
GoͷΠςϨʔλ
range over int
range over int 39 Go1.22Ҏ߱ Go1.22Ҏલ
range over func
range over func 41 GoͷΠςϨʔλͷσϑΝΫτελϯμʔυ
v1.23ҎલͷΠςϨʔλ 42 database/sql.Rows archive/tar.Reader.Next
range over func 43 ҎԼͷγάωνϟͷؔΛrangeͰ෮ॲཧͰ͖Δɻ
range over func 44
range over func 45 rangeͰyieldΛ༻͢Δ͜ͱ͕Ͱ͖ΔΑ͏ʹͳͬͨɻ
GoͷΠςϨʔλ 46 • PushελΠϧ : 1ͭͣͭσʔλΛ͢ • PullελΠϧ : 1ͭͣͭσʔλΛड͚औΔ
func(func()bool) 47
48 func(func(V)bool)
func(func(K, V)bool) 49
iterύοέʔδ
iterύοέʔδ 51 https://github.com/golang/go/tree/go1.23.0/src/iter 1.23ͰՃ͞Εͨ