Considering the
introduction of the
anonymous function syntax
sugar into Go
!ZVSPZPSP
(Pʹແ໊ؔͷҥߏจ͍ΕͨΒͲ͏ͳΔͷʁ
Slide 2
Slide 2 text
(Pͷແ໊ؔ
var f = func(x int) int { return x * 2 }
Slide 3
Slide 3 text
͍ΘΏΔ"SSPX'VODUJPO͕΄͍͠
var f = (x int) int => { return x * 2 }
Slide 4
Slide 4 text
ಈతܕ͖ͳݴޠͰʁ
const f = (x) => { return x * 2 }
+BWB4DSJQU
1ZUIPO
f = lambda x: x * 2
3VCZ
f = ->(x) { x * 2 }
Slide 5
Slide 5 text
੩తܕ͖ͳݴޠͰʁ
const f = (x:number): number =>
{ return x * 2 }
5ZQF4DSJQU
+BWB
4DBMB
Function f =
(Integer x) -> { return x * 2; };
val f: (Int) => Int = (x) =>
{ x * 2 }
Slide 6
Slide 6 text
(PͰ͜ΜͳܗͷߏจʹͳΓͦ͏
(name type, …) type => { function body }
ؔͷܕͰ͔͚ΔΑ͏ʹ͠Α͏
var f: ->(int) int =
->(x int) int { return x * 2 }
Slide 22
Slide 22 text
%FNP
package main
import "fmt"
func main() {
f := ->(x int, y int) int { return x + y }
fmt.Printf("%d\n", f(3, 4))
fmt.Printf("%d", higherFunc(f))
}
func higherFunc(f ->(x int, y int) int) int {
return f(1, 2)
}
Slide 23
Slide 23 text
Ͱɺ͑ͦ͏ʁ
Slide 24
Slide 24 text
ΈΜͳେ͖IUUQ4FSWFS
http.HandleFunc("/",
->(w http.ResponseWriter, r *http.Request) { ... })
Slide 25
Slide 25 text
͠(Pʹ(FOFSJDT͕ೖͬͨΒ
var arr = [1, 2, 3]
arr.map( ->(x int) int { return x * 2 })
Slide 26
Slide 26 text
AGVODAΑΓจࣈݮͬͨ
Slide 27
Slide 27 text
͋Μ·ΓมΘΒͳ͍ͷͰʜʜ
Slide 28
Slide 28 text
ͨͱ͑ɺ+BWBͰҾͷܕએݴΛ
লུͰ͖Δ
↓
+BWB
Function f =
(Integer x) -> { return x * 2; };
Function f =
(x) -> { return x * 2; };
Slide 29
Slide 29 text
4DBMBͰฦΓܕΛਪͯ͘͠ΕΔ
↓
4DBMB
val f: Int => Int = (x: Int) => { x * 2 }
val f = (x: Int) => { x * 2 }
Slide 30
Slide 30 text
SFUVSOΛলུͰ͖Δݴޠଟ͍
↓
+BWB
Function f =
(x) -> { return x * 2; };
Function f =
(x) -> { x * 2; };