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
130
【Go言語】クロージャ
一部Rustのとこも出てきます
Tomoki Ota
October 04, 2024
Tweet
Share
More Decks by Tomoki Ota
See All by Tomoki Ota
アーキテクチャの価値
tomo1227
0
26
アーキテクチャとビジネスロジック
tomo1227
0
25
【Go言語】テスト
tomo1227
0
15
【Go言語】イテレータ
tomo1227
0
17
【Go言語】エラーハンドリング
tomo1227
0
18
AIに淘汰されないようにするには?
tomo1227
0
25
【Go言語】range
tomo1227
0
9
【Go言語】break
tomo1227
0
21
【Go言語】反復処理
tomo1227
0
10
Other Decks in Programming
See All in Programming
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
350
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
Welcome JSConf.jp 2024
yosuke_furukawa
PRO
0
150
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
120
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.8k
Vapor Revolution
kazupon
2
350
Better Code Design in PHP
afilina
PRO
0
130
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
Jakarta EE meets AI
ivargrimstad
0
800
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
Contemporary Test Cases
maaretp
0
140
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
380
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
How to Ace a Technical Interview
jacobian
276
23k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Side Projects
sachag
452
42k
The Pragmatic Product Professional
lauravandoore
31
6.3k
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ͰՃ͞Εͨ