Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b89f30b

Browse files
committed
fixes 3
1 parent 267f261 commit b89f30b

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

‎closures/closure.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package main
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"strconv"
6+
)
47

58
func main(){
69

@@ -9,12 +12,31 @@ func main(){
912
fmt.Println(clouser1())
1013
fmt.Println(clouser1())
1114

15+
// function as param
16+
fmt.Println(myFunc(testFunc,123))
17+
1218
}
1319

20+
1421
func closure_example() func() int{
1522
var i=0
1623
return func() int{
1724
i++;
1825
return i
1926
}
2027
}
28+
29+
// function as param
30+
type convert func(int) string
31+
32+
func testFunc(val int) string{
33+
return "The value is:"+ strconv.Itoa(val)
34+
}
35+
36+
func myFunc(fn convert, val int) string{
37+
return fn(val)
38+
}
39+
40+
func temp2() {
41+
42+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /