Skip to content

Commit 7573265

Browse files
Merge pull request #70 from logic-building/restptr
Added function RestPtr
2 parents 2f75b93 + c425e3e commit 7573265

File tree

5 files changed

+935
-0
lines changed

5 files changed

+935
-0
lines changed

fp/restptr.go

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
package fp
2+
3+
4+
// RestInt removes 1st item of the list and return new list having rest of the items
5+
func RestIntPtr(l []*int) []*int {
6+
if l == nil {
7+
return []*int{}
8+
}
9+
10+
len := len(l)
11+
if len == 0 || len == 1 {
12+
return []*int{}
13+
}
14+
15+
newList := make([]*int, len-1)
16+
17+
for i, v := range l[1:] {
18+
newList[i] = v
19+
}
20+
21+
return newList
22+
}
23+
24+
25+
// RestInt64 removes 1st item of the list and return new list having rest of the items
26+
func RestInt64Ptr(l []*int64) []*int64 {
27+
if l == nil {
28+
return []*int64{}
29+
}
30+
31+
len := len(l)
32+
if len == 0 || len == 1 {
33+
return []*int64{}
34+
}
35+
36+
newList := make([]*int64, len-1)
37+
38+
for i, v := range l[1:] {
39+
newList[i] = v
40+
}
41+
42+
return newList
43+
}
44+
45+
46+
// RestInt32 removes 1st item of the list and return new list having rest of the items
47+
func RestInt32Ptr(l []*int32) []*int32 {
48+
if l == nil {
49+
return []*int32{}
50+
}
51+
52+
len := len(l)
53+
if len == 0 || len == 1 {
54+
return []*int32{}
55+
}
56+
57+
newList := make([]*int32, len-1)
58+
59+
for i, v := range l[1:] {
60+
newList[i] = v
61+
}
62+
63+
return newList
64+
}
65+
66+
67+
// RestInt16 removes 1st item of the list and return new list having rest of the items
68+
func RestInt16Ptr(l []*int16) []*int16 {
69+
if l == nil {
70+
return []*int16{}
71+
}
72+
73+
len := len(l)
74+
if len == 0 || len == 1 {
75+
return []*int16{}
76+
}
77+
78+
newList := make([]*int16, len-1)
79+
80+
for i, v := range l[1:] {
81+
newList[i] = v
82+
}
83+
84+
return newList
85+
}
86+
87+
88+
// RestInt8 removes 1st item of the list and return new list having rest of the items
89+
func RestInt8Ptr(l []*int8) []*int8 {
90+
if l == nil {
91+
return []*int8{}
92+
}
93+
94+
len := len(l)
95+
if len == 0 || len == 1 {
96+
return []*int8{}
97+
}
98+
99+
newList := make([]*int8, len-1)
100+
101+
for i, v := range l[1:] {
102+
newList[i] = v
103+
}
104+
105+
return newList
106+
}
107+
108+
109+
// RestUint removes 1st item of the list and return new list having rest of the items
110+
func RestUintPtr(l []*uint) []*uint {
111+
if l == nil {
112+
return []*uint{}
113+
}
114+
115+
len := len(l)
116+
if len == 0 || len == 1 {
117+
return []*uint{}
118+
}
119+
120+
newList := make([]*uint, len-1)
121+
122+
for i, v := range l[1:] {
123+
newList[i] = v
124+
}
125+
126+
return newList
127+
}
128+
129+
130+
// RestUint64 removes 1st item of the list and return new list having rest of the items
131+
func RestUint64Ptr(l []*uint64) []*uint64 {
132+
if l == nil {
133+
return []*uint64{}
134+
}
135+
136+
len := len(l)
137+
if len == 0 || len == 1 {
138+
return []*uint64{}
139+
}
140+
141+
newList := make([]*uint64, len-1)
142+
143+
for i, v := range l[1:] {
144+
newList[i] = v
145+
}
146+
147+
return newList
148+
}
149+
150+
151+
// RestUint32 removes 1st item of the list and return new list having rest of the items
152+
func RestUint32Ptr(l []*uint32) []*uint32 {
153+
if l == nil {
154+
return []*uint32{}
155+
}
156+
157+
len := len(l)
158+
if len == 0 || len == 1 {
159+
return []*uint32{}
160+
}
161+
162+
newList := make([]*uint32, len-1)
163+
164+
for i, v := range l[1:] {
165+
newList[i] = v
166+
}
167+
168+
return newList
169+
}
170+
171+
172+
// RestUint16 removes 1st item of the list and return new list having rest of the items
173+
func RestUint16Ptr(l []*uint16) []*uint16 {
174+
if l == nil {
175+
return []*uint16{}
176+
}
177+
178+
len := len(l)
179+
if len == 0 || len == 1 {
180+
return []*uint16{}
181+
}
182+
183+
newList := make([]*uint16, len-1)
184+
185+
for i, v := range l[1:] {
186+
newList[i] = v
187+
}
188+
189+
return newList
190+
}
191+
192+
193+
// RestUint8 removes 1st item of the list and return new list having rest of the items
194+
func RestUint8Ptr(l []*uint8) []*uint8 {
195+
if l == nil {
196+
return []*uint8{}
197+
}
198+
199+
len := len(l)
200+
if len == 0 || len == 1 {
201+
return []*uint8{}
202+
}
203+
204+
newList := make([]*uint8, len-1)
205+
206+
for i, v := range l[1:] {
207+
newList[i] = v
208+
}
209+
210+
return newList
211+
}
212+
213+
214+
// RestStr removes 1st item of the list and return new list having rest of the items
215+
func RestStrPtr(l []*string) []*string {
216+
if l == nil {
217+
return []*string{}
218+
}
219+
220+
len := len(l)
221+
if len == 0 || len == 1 {
222+
return []*string{}
223+
}
224+
225+
newList := make([]*string, len-1)
226+
227+
for i, v := range l[1:] {
228+
newList[i] = v
229+
}
230+
231+
return newList
232+
}
233+
234+
235+
// RestBool removes 1st item of the list and return new list having rest of the items
236+
func RestBoolPtr(l []*bool) []*bool {
237+
if l == nil {
238+
return []*bool{}
239+
}
240+
241+
len := len(l)
242+
if len == 0 || len == 1 {
243+
return []*bool{}
244+
}
245+
246+
newList := make([]*bool, len-1)
247+
248+
for i, v := range l[1:] {
249+
newList[i] = v
250+
}
251+
252+
return newList
253+
}
254+
255+
256+
// RestFloat32 removes 1st item of the list and return new list having rest of the items
257+
func RestFloat32Ptr(l []*float32) []*float32 {
258+
if l == nil {
259+
return []*float32{}
260+
}
261+
262+
len := len(l)
263+
if len == 0 || len == 1 {
264+
return []*float32{}
265+
}
266+
267+
newList := make([]*float32, len-1)
268+
269+
for i, v := range l[1:] {
270+
newList[i] = v
271+
}
272+
273+
return newList
274+
}
275+
276+
277+
// RestFloat64 removes 1st item of the list and return new list having rest of the items
278+
func RestFloat64Ptr(l []*float64) []*float64 {
279+
if l == nil {
280+
return []*float64{}
281+
}
282+
283+
len := len(l)
284+
if len == 0 || len == 1 {
285+
return []*float64{}
286+
}
287+
288+
newList := make([]*float64, len-1)
289+
290+
for i, v := range l[1:] {
291+
newList[i] = v
292+
}
293+
294+
return newList
295+
}

0 commit comments

Comments
 (0)