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 267f261

Browse files
committed
fixes 3
1 parent cb5ba2f commit 267f261

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

‎closures/anonymous_function.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//package clousres
2+
package main
3+
4+
5+
import "fmt"
6+
7+
//func main(){
8+
// print_from_anynomous_function("anonymous function")
9+
//}
10+
11+
func print_from_anynomous_function(something string){
12+
// this is anonymous function
13+
func (str string){
14+
fmt.Println("Hello from",str)
15+
}(something)
16+
}

‎closures/closure.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main(){
6+
7+
clouser1:=closure_example()
8+
9+
fmt.Println(clouser1())
10+
fmt.Println(clouser1())
11+
12+
}
13+
14+
func closure_example() func() int{
15+
var i=0
16+
return func() int{
17+
i++;
18+
return i
19+
}
20+
}

‎closures/normal_function.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func print(someything string){
6+
7+
fmt.Println(someything)
8+
}

‎closures/return_anonymous_function.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import "fmt"
4+
5+
//func main() {
6+
// //returnedFunction:=return_anonymous_fucntion()
7+
// //returnedFunction("Printing from a function that returns a function")
8+
// return_anonymous_fucntion()("Printing from a function that returns a function")
9+
//}
10+
11+
func return_anonymous_fucntion() func(somethig string){
12+
return func(str string){
13+
fmt.Println(str)
14+
}
15+
}

0 commit comments

Comments
(0)

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