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
Tomoki Ota
October 04, 2024
Programming
0
290
【Go言語】クロージャ
一部Rustのとこも出てきます
Tomoki Ota
October 04, 2024
Tweet
Share
More Decks by Tomoki Ota
See All by Tomoki Ota
アーキテクチャの価値
tomo1227
0
110
アーキテクチャとビジネスロジック
tomo1227
0
110
【Go言語】テスト
tomo1227
0
72
【Go言語】イテレータ
tomo1227
0
91
【Go言語】エラーハンドリング
tomo1227
0
74
AIに淘汰されないようにするには?
tomo1227
0
75
【Go言語】range
tomo1227
0
83
【Go言語】break
tomo1227
0
76
【Go言語】反復処理
tomo1227
0
53
Other Decks in Programming
See All in Programming
CSC307 Lecture 03
javiergs
PRO
1
490
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
7
2k
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
400
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
450
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
140
AI巻き込み型コードレビューのススメ
nealle
0
130
CSC307 Lecture 08
javiergs
PRO
0
670
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
20
6.9k
「ブロックテーマでは再現できない」は本当か?
inc2734
0
700
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
150
AtCoder Conference 2025
shindannin
0
1k
Fragmented Architectures
denyspoltorak
0
150
Featured
See All Featured
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
100
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.9k
What's in a price? How to price your products and services
michaelherold
247
13k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
60
42k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
0
270
A Modern Web Designer's Workflow
chriscoyier
698
190k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
240
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.6k
The Spectacular Lies of Maps
axbom
PRO
1
520
How to Think Like a Performance Engineer
csswizardry
28
2.4k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.7k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
290
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ͰՃ͞Εͨ