-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpop.go
193 lines (154 loc) · 6.15 KB
/
pop.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package slice
import "errors"
// PopBool removes and returns the last value a bool slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopBool(a []bool) (bool, []bool, error) {
if len(a) == 0 {
return false, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopByte removes and returns the last value a byte slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopByte(a []byte) (byte, []byte, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopComplex128 removes and returns the last value a complex128 slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopComplex128(a []complex128) (complex128, []complex128, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopComplex64 removes and returns the last value a complex64 slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopComplex64(a []complex64) (complex64, []complex64, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopFloat32 removes and returns the last value a float32 slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopFloat32(a []float32) (float32, []float32, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopFloat64 removes and returns the last value a float64 slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopFloat64(a []float64) (float64, []float64, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopInt removes and returns the last value a int slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopInt(a []int) (int, []int, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopInt16 removes and returns the last value a int16 slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopInt16(a []int16) (int16, []int16, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopInt32 removes and returns the last value a int32 slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopInt32(a []int32) (int32, []int32, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopInt64 removes and returns the last value a int64 slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopInt64(a []int64) (int64, []int64, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopInt8 removes and returns the last value a int8 slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopInt8(a []int8) (int8, []int8, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopRune removes and returns the last value a rune slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopRune(a []rune) (rune, []rune, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopString removes and returns the last value a string slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopString(a []string) (string, []string, error) {
if len(a) == 0 {
return "", nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopUint removes and returns the last value a uint slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopUint(a []uint) (uint, []uint, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopUint16 removes and returns the last value a uint16 slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopUint16(a []uint16) (uint16, []uint16, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopUint32 removes and returns the last value a uint32 slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopUint32(a []uint32) (uint32, []uint32, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopUint64 removes and returns the last value a uint64 slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopUint64(a []uint64) (uint64, []uint64, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopUint8 removes and returns the last value a uint8 slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopUint8(a []uint8) (uint8, []uint8, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}
// PopUintptr removes and returns the last value a uintptr slice and the remaining slice.
// An error is returned in case of a nil or empty slice.
func PopUintptr(a []uintptr) (uintptr, []uintptr, error) {
if len(a) == 0 {
return 0, nil, errors.New("Cannot pop from a nil or empty slice")
}
return a[len(a)-1], a[:len(a)-1], nil
}