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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Tomoki Ota
October 04, 2024
Programming
0
300
【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
74
【Go言語】イテレータ
tomo1227
0
95
【Go言語】エラーハンドリング
tomo1227
0
78
AIに淘汰されないようにするには?
tomo1227
0
76
【Go言語】range
tomo1227
0
83
【Go言語】break
tomo1227
0
77
【Go言語】反復処理
tomo1227
0
55
Other Decks in Programming
See All in Programming
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
5
830
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
160
プロダクトオーナーから見たSOC2 _SOC2ゆるミートアップ#2
kekekenta
0
240
CSC307 Lecture 03
javiergs
PRO
1
500
CSC307 Lecture 08
javiergs
PRO
0
680
Fluid Templating in TYPO3 14
s2b
0
140
要求定義・仕様記述・設計・検証の手引き - 理論から学ぶ明確で統一された成果物定義
orgachem
PRO
1
290
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
320
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
150
Raku Raku Notion 20260128
hareyakayuruyaka
0
390
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
ぼくの開発環境2026
yuzneri
0
270
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
The Invisible Side of Design
smashingmag
302
51k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.7k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
62
50k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
440
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
460
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
1
1.3k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
130
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.1k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
920
Paper Plane (Part 1)
katiecoart
PRO
0
4.4k
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ͰՃ͞Εͨ