|
| 1 | +package fp |
| 2 | + |
| 3 | +// DedupeInt Returns a new list removing consecutive duplicates in list. |
| 4 | +func DedupeInt(list []int) []int { |
| 5 | + var newList []int |
| 6 | + |
| 7 | + lenList := len(list) |
| 8 | + for i := 0; i < lenList; i++ { |
| 9 | + if i+1 < lenList && list[i] == list[i+1] { |
| 10 | + continue |
| 11 | + } |
| 12 | + newList = append(newList, list[i]) |
| 13 | + } |
| 14 | + return newList |
| 15 | +} |
| 16 | + |
| 17 | +// DedupeIntPtr Returns a new list removing consecutive duplicates in list. |
| 18 | +func DedupeIntPtr(list []*int) []*int { |
| 19 | + var newList []*int |
| 20 | + |
| 21 | + lenList := len(list) |
| 22 | + for i := 0; i < lenList; i++ { |
| 23 | + if i+1 < lenList && *list[i] == *list[i+1] { |
| 24 | + continue |
| 25 | + } |
| 26 | + newList = append(newList, list[i]) |
| 27 | + } |
| 28 | + return newList |
| 29 | +} |
| 30 | + |
| 31 | +// DedupeInt64 Returns a new list removing consecutive duplicates in list. |
| 32 | +func DedupeInt64(list []int64) []int64 { |
| 33 | + var newList []int64 |
| 34 | + |
| 35 | + lenList := len(list) |
| 36 | + for i := 0; i < lenList; i++ { |
| 37 | + if i+1 < lenList && list[i] == list[i+1] { |
| 38 | + continue |
| 39 | + } |
| 40 | + newList = append(newList, list[i]) |
| 41 | + } |
| 42 | + return newList |
| 43 | +} |
| 44 | + |
| 45 | +// DedupeInt64Ptr Returns a new list removing consecutive duplicates in list. |
| 46 | +func DedupeInt64Ptr(list []*int64) []*int64 { |
| 47 | + var newList []*int64 |
| 48 | + |
| 49 | + lenList := len(list) |
| 50 | + for i := 0; i < lenList; i++ { |
| 51 | + if i+1 < lenList && *list[i] == *list[i+1] { |
| 52 | + continue |
| 53 | + } |
| 54 | + newList = append(newList, list[i]) |
| 55 | + } |
| 56 | + return newList |
| 57 | +} |
| 58 | + |
| 59 | +// DedupeInt32 Returns a new list removing consecutive duplicates in list. |
| 60 | +func DedupeInt32(list []int32) []int32 { |
| 61 | + var newList []int32 |
| 62 | + |
| 63 | + lenList := len(list) |
| 64 | + for i := 0; i < lenList; i++ { |
| 65 | + if i+1 < lenList && list[i] == list[i+1] { |
| 66 | + continue |
| 67 | + } |
| 68 | + newList = append(newList, list[i]) |
| 69 | + } |
| 70 | + return newList |
| 71 | +} |
| 72 | + |
| 73 | +// DedupeInt32Ptr Returns a new list removing consecutive duplicates in list. |
| 74 | +func DedupeInt32Ptr(list []*int32) []*int32 { |
| 75 | + var newList []*int32 |
| 76 | + |
| 77 | + lenList := len(list) |
| 78 | + for i := 0; i < lenList; i++ { |
| 79 | + if i+1 < lenList && *list[i] == *list[i+1] { |
| 80 | + continue |
| 81 | + } |
| 82 | + newList = append(newList, list[i]) |
| 83 | + } |
| 84 | + return newList |
| 85 | +} |
| 86 | + |
| 87 | +// DedupeInt16 Returns a new list removing consecutive duplicates in list. |
| 88 | +func DedupeInt16(list []int16) []int16 { |
| 89 | + var newList []int16 |
| 90 | + |
| 91 | + lenList := len(list) |
| 92 | + for i := 0; i < lenList; i++ { |
| 93 | + if i+1 < lenList && list[i] == list[i+1] { |
| 94 | + continue |
| 95 | + } |
| 96 | + newList = append(newList, list[i]) |
| 97 | + } |
| 98 | + return newList |
| 99 | +} |
| 100 | + |
| 101 | +// DedupeInt16Ptr Returns a new list removing consecutive duplicates in list. |
| 102 | +func DedupeInt16Ptr(list []*int16) []*int16 { |
| 103 | + var newList []*int16 |
| 104 | + |
| 105 | + lenList := len(list) |
| 106 | + for i := 0; i < lenList; i++ { |
| 107 | + if i+1 < lenList && *list[i] == *list[i+1] { |
| 108 | + continue |
| 109 | + } |
| 110 | + newList = append(newList, list[i]) |
| 111 | + } |
| 112 | + return newList |
| 113 | +} |
| 114 | + |
| 115 | +// DedupeInt8 Returns a new list removing consecutive duplicates in list. |
| 116 | +func DedupeInt8(list []int8) []int8 { |
| 117 | + var newList []int8 |
| 118 | + |
| 119 | + lenList := len(list) |
| 120 | + for i := 0; i < lenList; i++ { |
| 121 | + if i+1 < lenList && list[i] == list[i+1] { |
| 122 | + continue |
| 123 | + } |
| 124 | + newList = append(newList, list[i]) |
| 125 | + } |
| 126 | + return newList |
| 127 | +} |
| 128 | + |
| 129 | +// DedupeInt8Ptr Returns a new list removing consecutive duplicates in list. |
| 130 | +func DedupeInt8Ptr(list []*int8) []*int8 { |
| 131 | + var newList []*int8 |
| 132 | + |
| 133 | + lenList := len(list) |
| 134 | + for i := 0; i < lenList; i++ { |
| 135 | + if i+1 < lenList && *list[i] == *list[i+1] { |
| 136 | + continue |
| 137 | + } |
| 138 | + newList = append(newList, list[i]) |
| 139 | + } |
| 140 | + return newList |
| 141 | +} |
| 142 | + |
| 143 | +// DedupeUint Returns a new list removing consecutive duplicates in list. |
| 144 | +func DedupeUint(list []uint) []uint { |
| 145 | + var newList []uint |
| 146 | + |
| 147 | + lenList := len(list) |
| 148 | + for i := 0; i < lenList; i++ { |
| 149 | + if i+1 < lenList && list[i] == list[i+1] { |
| 150 | + continue |
| 151 | + } |
| 152 | + newList = append(newList, list[i]) |
| 153 | + } |
| 154 | + return newList |
| 155 | +} |
| 156 | + |
| 157 | +// DedupeUintPtr Returns a new list removing consecutive duplicates in list. |
| 158 | +func DedupeUintPtr(list []*uint) []*uint { |
| 159 | + var newList []*uint |
| 160 | + |
| 161 | + lenList := len(list) |
| 162 | + for i := 0; i < lenList; i++ { |
| 163 | + if i+1 < lenList && *list[i] == *list[i+1] { |
| 164 | + continue |
| 165 | + } |
| 166 | + newList = append(newList, list[i]) |
| 167 | + } |
| 168 | + return newList |
| 169 | +} |
| 170 | + |
| 171 | +// DedupeUint64 Returns a new list removing consecutive duplicates in list. |
| 172 | +func DedupeUint64(list []uint64) []uint64 { |
| 173 | + var newList []uint64 |
| 174 | + |
| 175 | + lenList := len(list) |
| 176 | + for i := 0; i < lenList; i++ { |
| 177 | + if i+1 < lenList && list[i] == list[i+1] { |
| 178 | + continue |
| 179 | + } |
| 180 | + newList = append(newList, list[i]) |
| 181 | + } |
| 182 | + return newList |
| 183 | +} |
| 184 | + |
| 185 | +// DedupeUint64Ptr Returns a new list removing consecutive duplicates in list. |
| 186 | +func DedupeUint64Ptr(list []*uint64) []*uint64 { |
| 187 | + var newList []*uint64 |
| 188 | + |
| 189 | + lenList := len(list) |
| 190 | + for i := 0; i < lenList; i++ { |
| 191 | + if i+1 < lenList && *list[i] == *list[i+1] { |
| 192 | + continue |
| 193 | + } |
| 194 | + newList = append(newList, list[i]) |
| 195 | + } |
| 196 | + return newList |
| 197 | +} |
| 198 | + |
| 199 | +// DedupeUint32 Returns a new list removing consecutive duplicates in list. |
| 200 | +func DedupeUint32(list []uint32) []uint32 { |
| 201 | + var newList []uint32 |
| 202 | + |
| 203 | + lenList := len(list) |
| 204 | + for i := 0; i < lenList; i++ { |
| 205 | + if i+1 < lenList && list[i] == list[i+1] { |
| 206 | + continue |
| 207 | + } |
| 208 | + newList = append(newList, list[i]) |
| 209 | + } |
| 210 | + return newList |
| 211 | +} |
| 212 | + |
| 213 | +// DedupeUint32Ptr Returns a new list removing consecutive duplicates in list. |
| 214 | +func DedupeUint32Ptr(list []*uint32) []*uint32 { |
| 215 | + var newList []*uint32 |
| 216 | + |
| 217 | + lenList := len(list) |
| 218 | + for i := 0; i < lenList; i++ { |
| 219 | + if i+1 < lenList && *list[i] == *list[i+1] { |
| 220 | + continue |
| 221 | + } |
| 222 | + newList = append(newList, list[i]) |
| 223 | + } |
| 224 | + return newList |
| 225 | +} |
| 226 | + |
| 227 | +// DedupeUint16 Returns a new list removing consecutive duplicates in list. |
| 228 | +func DedupeUint16(list []uint16) []uint16 { |
| 229 | + var newList []uint16 |
| 230 | + |
| 231 | + lenList := len(list) |
| 232 | + for i := 0; i < lenList; i++ { |
| 233 | + if i+1 < lenList && list[i] == list[i+1] { |
| 234 | + continue |
| 235 | + } |
| 236 | + newList = append(newList, list[i]) |
| 237 | + } |
| 238 | + return newList |
| 239 | +} |
| 240 | + |
| 241 | +// DedupeUint16Ptr Returns a new list removing consecutive duplicates in list. |
| 242 | +func DedupeUint16Ptr(list []*uint16) []*uint16 { |
| 243 | + var newList []*uint16 |
| 244 | + |
| 245 | + lenList := len(list) |
| 246 | + for i := 0; i < lenList; i++ { |
| 247 | + if i+1 < lenList && *list[i] == *list[i+1] { |
| 248 | + continue |
| 249 | + } |
| 250 | + newList = append(newList, list[i]) |
| 251 | + } |
| 252 | + return newList |
| 253 | +} |
| 254 | + |
| 255 | +// DedupeUint8 Returns a new list removing consecutive duplicates in list. |
| 256 | +func DedupeUint8(list []uint8) []uint8 { |
| 257 | + var newList []uint8 |
| 258 | + |
| 259 | + lenList := len(list) |
| 260 | + for i := 0; i < lenList; i++ { |
| 261 | + if i+1 < lenList && list[i] == list[i+1] { |
| 262 | + continue |
| 263 | + } |
| 264 | + newList = append(newList, list[i]) |
| 265 | + } |
| 266 | + return newList |
| 267 | +} |
| 268 | + |
| 269 | +// DedupeUint8Ptr Returns a new list removing consecutive duplicates in list. |
| 270 | +func DedupeUint8Ptr(list []*uint8) []*uint8 { |
| 271 | + var newList []*uint8 |
| 272 | + |
| 273 | + lenList := len(list) |
| 274 | + for i := 0; i < lenList; i++ { |
| 275 | + if i+1 < lenList && *list[i] == *list[i+1] { |
| 276 | + continue |
| 277 | + } |
| 278 | + newList = append(newList, list[i]) |
| 279 | + } |
| 280 | + return newList |
| 281 | +} |
| 282 | + |
| 283 | +// DedupeStr Returns a new list removing consecutive duplicates in list. |
| 284 | +func DedupeStr(list []string) []string { |
| 285 | + var newList []string |
| 286 | + |
| 287 | + lenList := len(list) |
| 288 | + for i := 0; i < lenList; i++ { |
| 289 | + if i+1 < lenList && list[i] == list[i+1] { |
| 290 | + continue |
| 291 | + } |
| 292 | + newList = append(newList, list[i]) |
| 293 | + } |
| 294 | + return newList |
| 295 | +} |
| 296 | + |
| 297 | +// DedupeStrPtr Returns a new list removing consecutive duplicates in list. |
| 298 | +func DedupeStrPtr(list []*string) []*string { |
| 299 | + var newList []*string |
| 300 | + |
| 301 | + lenList := len(list) |
| 302 | + for i := 0; i < lenList; i++ { |
| 303 | + if i+1 < lenList && *list[i] == *list[i+1] { |
| 304 | + continue |
| 305 | + } |
| 306 | + newList = append(newList, list[i]) |
| 307 | + } |
| 308 | + return newList |
| 309 | +} |
| 310 | + |
| 311 | +// DedupeBool Returns a new list removing consecutive duplicates in list. |
| 312 | +func DedupeBool(list []bool) []bool { |
| 313 | + var newList []bool |
| 314 | + |
| 315 | + lenList := len(list) |
| 316 | + for i := 0; i < lenList; i++ { |
| 317 | + if i+1 < lenList && list[i] == list[i+1] { |
| 318 | + continue |
| 319 | + } |
| 320 | + newList = append(newList, list[i]) |
| 321 | + } |
| 322 | + return newList |
| 323 | +} |
| 324 | + |
| 325 | +// DedupeBoolPtr Returns a new list removing consecutive duplicates in list. |
| 326 | +func DedupeBoolPtr(list []*bool) []*bool { |
| 327 | + var newList []*bool |
| 328 | + |
| 329 | + lenList := len(list) |
| 330 | + for i := 0; i < lenList; i++ { |
| 331 | + if i+1 < lenList && *list[i] == *list[i+1] { |
| 332 | + continue |
| 333 | + } |
| 334 | + newList = append(newList, list[i]) |
| 335 | + } |
| 336 | + return newList |
| 337 | +} |
| 338 | + |
| 339 | +// DedupeFloat32 Returns a new list removing consecutive duplicates in list. |
| 340 | +func DedupeFloat32(list []float32) []float32 { |
| 341 | + var newList []float32 |
| 342 | + |
| 343 | + lenList := len(list) |
| 344 | + for i := 0; i < lenList; i++ { |
| 345 | + if i+1 < lenList && list[i] == list[i+1] { |
| 346 | + continue |
| 347 | + } |
| 348 | + newList = append(newList, list[i]) |
| 349 | + } |
| 350 | + return newList |
| 351 | +} |
| 352 | + |
| 353 | +// DedupeFloat32Ptr Returns a new list removing consecutive duplicates in list. |
| 354 | +func DedupeFloat32Ptr(list []*float32) []*float32 { |
| 355 | + var newList []*float32 |
| 356 | + |
| 357 | + lenList := len(list) |
| 358 | + for i := 0; i < lenList; i++ { |
| 359 | + if i+1 < lenList && *list[i] == *list[i+1] { |
| 360 | + continue |
| 361 | + } |
| 362 | + newList = append(newList, list[i]) |
| 363 | + } |
| 364 | + return newList |
| 365 | +} |
| 366 | + |
| 367 | +// DedupeFloat64 Returns a new list removing consecutive duplicates in list. |
| 368 | +func DedupeFloat64(list []float64) []float64 { |
| 369 | + var newList []float64 |
| 370 | + |
| 371 | + lenList := len(list) |
| 372 | + for i := 0; i < lenList; i++ { |
| 373 | + if i+1 < lenList && list[i] == list[i+1] { |
| 374 | + continue |
| 375 | + } |
| 376 | + newList = append(newList, list[i]) |
| 377 | + } |
| 378 | + return newList |
| 379 | +} |
| 380 | + |
| 381 | +// DedupeFloat64Ptr Returns a new list removing consecutive duplicates in list. |
| 382 | +func DedupeFloat64Ptr(list []*float64) []*float64 { |
| 383 | + var newList []*float64 |
| 384 | + |
| 385 | + lenList := len(list) |
| 386 | + for i := 0; i < lenList; i++ { |
| 387 | + if i+1 < lenList && *list[i] == *list[i+1] { |
| 388 | + continue |
| 389 | + } |
| 390 | + newList = append(newList, list[i]) |
| 391 | + } |
| 392 | + return newList |
| 393 | +} |
0 commit comments