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
260
【Go言語】クロージャ
一部Rustのとこも出てきます
Tomoki Ota
October 04, 2024
Tweet
Share
More Decks by Tomoki Ota
See All by Tomoki Ota
アーキテクチャの価値
tomo1227
0
94
アーキテクチャとビジネスロジック
tomo1227
0
93
【Go言語】テスト
tomo1227
0
53
【Go言語】イテレータ
tomo1227
0
70
【Go言語】エラーハンドリング
tomo1227
0
59
AIに淘汰されないようにするには?
tomo1227
0
59
【Go言語】range
tomo1227
0
64
【Go言語】break
tomo1227
0
62
【Go言語】反復処理
tomo1227
0
36
Other Decks in Programming
See All in Programming
contribution to astral-sh/uv
shunsock
0
440
Android16 Migration Stories ~Building a Pattern for Android OS upgrades~
reoandroider
0
130
CSC509 Lecture 07
javiergs
PRO
0
240
Things You Thought You Didn’t Need To Care About That Have a Big Impact On Your Job
hollycummins
0
250
技術的負債の正体を知って向き合う
irof
0
220
Catch Up: Go Style Guide Update
andpad
0
240
「ちょっと古いから」って避けてた技術書、今だからこそ読もう
mottyzzz
11
7k
iOSでSVG画像を扱う
kishikawakatsumi
0
150
その面倒な作業、「Dart」にやらせませんか? Flutter開発者のための業務効率化
yordgenome03
1
140
テーブル定義書の構造化抽出して、生成AIでDWH分析を試してみた / devio2025tokyo
kasacchiful
0
260
NixOS + Kubernetesで構築する自宅サーバーのすべて
ichi_h3
0
1.1k
Goで実践するドメイン駆動開発 AIと歩み始めた新規プロダクト開発の現在地
imkaoru
4
870
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
Balancing Empowerment & Direction
lara
5
700
Optimising Largest Contentful Paint
csswizardry
37
3.5k
Producing Creativity
orderedlist
PRO
347
40k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
Being A Developer After 40
akosma
91
590k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.2k
Practical Orchestrator
shlominoach
190
11k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.6k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
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ͰՃ͞Εͨ