-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhour23.go
144 lines (112 loc) · 1.93 KB
/
hour23.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package FortHours2
import "fmt"
var xolo int = 10
type person struct {
first string
last string
age int
}
type SQUARE struct {
side float64
}
func (sq SQUARE) area() float64 {
return sq.side * sq.side
}
type CIRCLE struct {
radius float64
}
func (cr CIRCLE) area() float64 {
return 3.14 * cr.radius * cr.radius
}
type SHAPE interface {
area() float64
}
func info(sh SHAPE) float64 {
return sh.area()
}
func hour23() {
defer foo2()
fmt.Println("I am just the defer")
fmt.Println(foo())
fmt.Println(bar())
fmt.Println(foo1(1,2,3,4,5,6,7,8,9,10))
fmt.Println(bar1([] int {1,2,3,4,5,6,7,8,9,}))
p1 := person{
"John",
"Lenon",
33,
}
fmt.Println(p1)
p1.speak()
square1 := SQUARE{
side: 4.0,
}
circle1 := CIRCLE{
radius: 7.0,
}
fmt.Println("Area of Square is", info(square1))
fmt.Println("Area of Circle is", info(circle1))
func() {
fmt.Println("Hello, playground I am in anonymous function")
}()
anony:= func() {
fmt.Println("Hello, playground I am anony, a function assigned to a variable")
}
anony()
x:= a()
x()
g := func(x int) int {
return x + 10
}
fmt.Println(foo5(g, 5))
fmt.Println(xolo)
something(8)
fmt.Println(xolo)
something(18)
fmt.Println(xolo)
}
func something(y int) {
xolo := y
fmt.Println(xolo)
}
func foo() int {
return 4
}
func bar() (int, string) {
return 12, "A word"
}
func foo1(x ...int) int {
sum := 0
for _,v := range x {
sum += v
}
return sum
}
func bar2(x []int) int {
sum := 0
for _, v := range x {
sum += v
}
return sum
}
func foo2() {
defer func(){
fmt.Println("I am the foo defer")
}()
fmt.Println("I am the foo")
}
func (p person) speak() {
fmt.Printf("I am %v %v, and I am %v years old", p.first, p.last, p.age)
}
func a() func() {
defer fmt.Println("a ended")
fmt.Println("a started")
return func(){
fmt.Println("Printing via anonymous function inside a")
}
}
func foo5(f func(x int) int, i int) int {
n := f(i)
n++
return n
}