github.com/optim-corp/cios-golang-sdk@v0.5.1/cios/stream_multiplecollectionlatest.go (about) 1 /* 2 * Collection utility of MultipleCollectionLatest Struct 3 * 4 * Generated by: Go Streamer 5 */ 6 7 package cios 8 9 import ( 10 "fmt" 11 "math" 12 "reflect" 13 "sort" 14 ) 15 16 type MultipleCollectionLatestStream []MultipleCollectionLatest 17 18 func MultipleCollectionLatestStreamOf(arg ...MultipleCollectionLatest) MultipleCollectionLatestStream { 19 return arg 20 } 21 func MultipleCollectionLatestStreamFrom(arg []MultipleCollectionLatest) MultipleCollectionLatestStream { 22 return arg 23 } 24 func CreateMultipleCollectionLatestStream(arg ...MultipleCollectionLatest) *MultipleCollectionLatestStream { 25 tmp := MultipleCollectionLatestStreamOf(arg...) 26 return &tmp 27 } 28 func GenerateMultipleCollectionLatestStream(arg []MultipleCollectionLatest) *MultipleCollectionLatestStream { 29 tmp := MultipleCollectionLatestStreamFrom(arg) 30 return &tmp 31 } 32 33 func (self *MultipleCollectionLatestStream) Add(arg MultipleCollectionLatest) *MultipleCollectionLatestStream { 34 return self.AddAll(arg) 35 } 36 func (self *MultipleCollectionLatestStream) AddAll(arg ...MultipleCollectionLatest) *MultipleCollectionLatestStream { 37 *self = append(*self, arg...) 38 return self 39 } 40 func (self *MultipleCollectionLatestStream) AddSafe(arg *MultipleCollectionLatest) *MultipleCollectionLatestStream { 41 if arg != nil { 42 self.Add(*arg) 43 } 44 return self 45 } 46 func (self *MultipleCollectionLatestStream) Aggregate(fn func(MultipleCollectionLatest, MultipleCollectionLatest) MultipleCollectionLatest) *MultipleCollectionLatestStream { 47 result := MultipleCollectionLatestStreamOf() 48 self.ForEach(func(v MultipleCollectionLatest, i int) { 49 if i == 0 { 50 result.Add(fn(MultipleCollectionLatest{}, v)) 51 } else { 52 result.Add(fn(result[i-1], v)) 53 } 54 }) 55 *self = result 56 return self 57 } 58 func (self *MultipleCollectionLatestStream) AllMatch(fn func(MultipleCollectionLatest, int) bool) bool { 59 for i, v := range *self { 60 if !fn(v, i) { 61 return false 62 } 63 } 64 return true 65 } 66 func (self *MultipleCollectionLatestStream) AnyMatch(fn func(MultipleCollectionLatest, int) bool) bool { 67 for i, v := range *self { 68 if fn(v, i) { 69 return true 70 } 71 } 72 return false 73 } 74 func (self *MultipleCollectionLatestStream) Clone() *MultipleCollectionLatestStream { 75 temp := make([]MultipleCollectionLatest, self.Len()) 76 copy(temp, *self) 77 return (*MultipleCollectionLatestStream)(&temp) 78 } 79 func (self *MultipleCollectionLatestStream) Copy() *MultipleCollectionLatestStream { 80 return self.Clone() 81 } 82 func (self *MultipleCollectionLatestStream) Concat(arg []MultipleCollectionLatest) *MultipleCollectionLatestStream { 83 return self.AddAll(arg...) 84 } 85 func (self *MultipleCollectionLatestStream) Contains(arg MultipleCollectionLatest) bool { 86 return self.FindIndex(func(_arg MultipleCollectionLatest, index int) bool { return reflect.DeepEqual(_arg, arg) }) != -1 87 } 88 func (self *MultipleCollectionLatestStream) Clean() *MultipleCollectionLatestStream { 89 *self = MultipleCollectionLatestStreamOf() 90 return self 91 } 92 func (self *MultipleCollectionLatestStream) Delete(index int) *MultipleCollectionLatestStream { 93 return self.DeleteRange(index, index) 94 } 95 func (self *MultipleCollectionLatestStream) DeleteRange(startIndex, endIndex int) *MultipleCollectionLatestStream { 96 *self = append((*self)[:startIndex], (*self)[endIndex+1:]...) 97 return self 98 } 99 func (self *MultipleCollectionLatestStream) Distinct() *MultipleCollectionLatestStream { 100 caches := map[string]bool{} 101 result := MultipleCollectionLatestStreamOf() 102 for _, v := range *self { 103 key := fmt.Sprintf("%+v", v) 104 if f, ok := caches[key]; ok { 105 if !f { 106 result = append(result, v) 107 } 108 } else if caches[key] = true; !f { 109 result = append(result, v) 110 } 111 112 } 113 *self = result 114 return self 115 } 116 func (self *MultipleCollectionLatestStream) Each(fn func(MultipleCollectionLatest)) *MultipleCollectionLatestStream { 117 for _, v := range *self { 118 fn(v) 119 } 120 return self 121 } 122 func (self *MultipleCollectionLatestStream) EachRight(fn func(MultipleCollectionLatest)) *MultipleCollectionLatestStream { 123 for i := self.Len() - 1; i >= 0; i-- { 124 fn(*self.Get(i)) 125 } 126 return self 127 } 128 func (self *MultipleCollectionLatestStream) Equals(arr []MultipleCollectionLatest) bool { 129 if (*self == nil) != (arr == nil) || len(*self) != len(arr) { 130 return false 131 } 132 for i := range *self { 133 if !reflect.DeepEqual((*self)[i], arr[i]) { 134 return false 135 } 136 } 137 return true 138 } 139 func (self *MultipleCollectionLatestStream) Filter(fn func(MultipleCollectionLatest, int) bool) *MultipleCollectionLatestStream { 140 result := MultipleCollectionLatestStreamOf() 141 for i, v := range *self { 142 if fn(v, i) { 143 result.Add(v) 144 } 145 } 146 *self = result 147 return self 148 } 149 func (self *MultipleCollectionLatestStream) FilterSlim(fn func(MultipleCollectionLatest, int) bool) *MultipleCollectionLatestStream { 150 result := MultipleCollectionLatestStreamOf() 151 caches := map[string]bool{} 152 for i, v := range *self { 153 key := fmt.Sprintf("%+v", v) 154 if f, ok := caches[key]; ok { 155 if f { 156 result.Add(v) 157 } 158 } else if caches[key] = fn(v, i); caches[key] { 159 result.Add(v) 160 161 } 162 } 163 *self = result 164 return self 165 } 166 func (self *MultipleCollectionLatestStream) Find(fn func(MultipleCollectionLatest, int) bool) *MultipleCollectionLatest { 167 if i := self.FindIndex(fn); -1 != i { 168 tmp := (*self)[i] 169 return &tmp 170 } 171 return nil 172 } 173 func (self *MultipleCollectionLatestStream) FindOr(fn func(MultipleCollectionLatest, int) bool, or MultipleCollectionLatest) MultipleCollectionLatest { 174 if v := self.Find(fn); v != nil { 175 return *v 176 } 177 return or 178 } 179 func (self *MultipleCollectionLatestStream) FindIndex(fn func(MultipleCollectionLatest, int) bool) int { 180 if self == nil { 181 return -1 182 } 183 for i, v := range *self { 184 if fn(v, i) { 185 return i 186 } 187 } 188 return -1 189 } 190 func (self *MultipleCollectionLatestStream) First() *MultipleCollectionLatest { 191 return self.Get(0) 192 } 193 func (self *MultipleCollectionLatestStream) FirstOr(arg MultipleCollectionLatest) MultipleCollectionLatest { 194 if v := self.Get(0); v != nil { 195 return *v 196 } 197 return arg 198 } 199 func (self *MultipleCollectionLatestStream) ForEach(fn func(MultipleCollectionLatest, int)) *MultipleCollectionLatestStream { 200 for i, v := range *self { 201 fn(v, i) 202 } 203 return self 204 } 205 func (self *MultipleCollectionLatestStream) ForEachRight(fn func(MultipleCollectionLatest, int)) *MultipleCollectionLatestStream { 206 for i := self.Len() - 1; i >= 0; i-- { 207 fn(*self.Get(i), i) 208 } 209 return self 210 } 211 func (self *MultipleCollectionLatestStream) GroupBy(fn func(MultipleCollectionLatest, int) string) map[string][]MultipleCollectionLatest { 212 m := map[string][]MultipleCollectionLatest{} 213 for i, v := range self.Val() { 214 key := fn(v, i) 215 m[key] = append(m[key], v) 216 } 217 return m 218 } 219 func (self *MultipleCollectionLatestStream) GroupByValues(fn func(MultipleCollectionLatest, int) string) [][]MultipleCollectionLatest { 220 var tmp [][]MultipleCollectionLatest 221 for _, v := range self.GroupBy(fn) { 222 tmp = append(tmp, v) 223 } 224 return tmp 225 } 226 func (self *MultipleCollectionLatestStream) IndexOf(arg MultipleCollectionLatest) int { 227 for index, _arg := range *self { 228 if reflect.DeepEqual(_arg, arg) { 229 return index 230 } 231 } 232 return -1 233 } 234 func (self *MultipleCollectionLatestStream) IsEmpty() bool { 235 return self.Len() == 0 236 } 237 func (self *MultipleCollectionLatestStream) IsPreset() bool { 238 return !self.IsEmpty() 239 } 240 func (self *MultipleCollectionLatestStream) Last() *MultipleCollectionLatest { 241 return self.Get(self.Len() - 1) 242 } 243 func (self *MultipleCollectionLatestStream) LastOr(arg MultipleCollectionLatest) MultipleCollectionLatest { 244 if v := self.Last(); v != nil { 245 return *v 246 } 247 return arg 248 } 249 func (self *MultipleCollectionLatestStream) Len() int { 250 if self == nil { 251 return 0 252 } 253 return len(*self) 254 } 255 func (self *MultipleCollectionLatestStream) Limit(limit int) *MultipleCollectionLatestStream { 256 self.Slice(0, limit) 257 return self 258 } 259 260 func (self *MultipleCollectionLatestStream) Map(fn func(MultipleCollectionLatest, int) interface{}) interface{} { 261 _array := make([]interface{}, 0, len(*self)) 262 for i, v := range *self { 263 _array = append(_array, fn(v, i)) 264 } 265 return _array 266 } 267 func (self *MultipleCollectionLatestStream) Map2Int(fn func(MultipleCollectionLatest, int) int) []int { 268 _array := make([]int, 0, len(*self)) 269 for i, v := range *self { 270 _array = append(_array, fn(v, i)) 271 } 272 return _array 273 } 274 func (self *MultipleCollectionLatestStream) Map2Int32(fn func(MultipleCollectionLatest, int) int32) []int32 { 275 _array := make([]int32, 0, len(*self)) 276 for i, v := range *self { 277 _array = append(_array, fn(v, i)) 278 } 279 return _array 280 } 281 func (self *MultipleCollectionLatestStream) Map2Int64(fn func(MultipleCollectionLatest, int) int64) []int64 { 282 _array := make([]int64, 0, len(*self)) 283 for i, v := range *self { 284 _array = append(_array, fn(v, i)) 285 } 286 return _array 287 } 288 func (self *MultipleCollectionLatestStream) Map2Float32(fn func(MultipleCollectionLatest, int) float32) []float32 { 289 _array := make([]float32, 0, len(*self)) 290 for i, v := range *self { 291 _array = append(_array, fn(v, i)) 292 } 293 return _array 294 } 295 func (self *MultipleCollectionLatestStream) Map2Float64(fn func(MultipleCollectionLatest, int) float64) []float64 { 296 _array := make([]float64, 0, len(*self)) 297 for i, v := range *self { 298 _array = append(_array, fn(v, i)) 299 } 300 return _array 301 } 302 func (self *MultipleCollectionLatestStream) Map2Bool(fn func(MultipleCollectionLatest, int) bool) []bool { 303 _array := make([]bool, 0, len(*self)) 304 for i, v := range *self { 305 _array = append(_array, fn(v, i)) 306 } 307 return _array 308 } 309 func (self *MultipleCollectionLatestStream) Map2Bytes(fn func(MultipleCollectionLatest, int) []byte) [][]byte { 310 _array := make([][]byte, 0, len(*self)) 311 for i, v := range *self { 312 _array = append(_array, fn(v, i)) 313 } 314 return _array 315 } 316 func (self *MultipleCollectionLatestStream) Map2String(fn func(MultipleCollectionLatest, int) string) []string { 317 _array := make([]string, 0, len(*self)) 318 for i, v := range *self { 319 _array = append(_array, fn(v, i)) 320 } 321 return _array 322 } 323 func (self *MultipleCollectionLatestStream) Max(fn func(MultipleCollectionLatest, int) float64) *MultipleCollectionLatest { 324 f := self.Get(0) 325 if f == nil { 326 return nil 327 } 328 m := fn(*f, 0) 329 index := 0 330 for i := 1; i < self.Len(); i++ { 331 v := fn(*self.Get(i), i) 332 m = math.Max(m, v) 333 if m == v { 334 index = i 335 } 336 } 337 return self.Get(index) 338 } 339 func (self *MultipleCollectionLatestStream) Min(fn func(MultipleCollectionLatest, int) float64) *MultipleCollectionLatest { 340 f := self.Get(0) 341 if f == nil { 342 return nil 343 } 344 m := fn(*f, 0) 345 index := 0 346 for i := 1; i < self.Len(); i++ { 347 v := fn(*self.Get(i), i) 348 m = math.Min(m, v) 349 if m == v { 350 index = i 351 } 352 } 353 return self.Get(index) 354 } 355 func (self *MultipleCollectionLatestStream) NoneMatch(fn func(MultipleCollectionLatest, int) bool) bool { 356 return !self.AnyMatch(fn) 357 } 358 func (self *MultipleCollectionLatestStream) Get(index int) *MultipleCollectionLatest { 359 if self.Len() > index && index >= 0 { 360 tmp := (*self)[index] 361 return &tmp 362 } 363 return nil 364 } 365 func (self *MultipleCollectionLatestStream) GetOr(index int, arg MultipleCollectionLatest) MultipleCollectionLatest { 366 if v := self.Get(index); v != nil { 367 return *v 368 } 369 return arg 370 } 371 func (self *MultipleCollectionLatestStream) Peek(fn func(*MultipleCollectionLatest, int)) *MultipleCollectionLatestStream { 372 for i, v := range *self { 373 fn(&v, i) 374 self.Set(i, v) 375 } 376 return self 377 } 378 379 380 func (self *MultipleCollectionLatestStream) Reduce(fn func(MultipleCollectionLatest, MultipleCollectionLatest, int) MultipleCollectionLatest) *MultipleCollectionLatestStream { 381 return self.ReduceInit(fn, MultipleCollectionLatest{}) 382 } 383 func (self *MultipleCollectionLatestStream) ReduceInit(fn func(MultipleCollectionLatest, MultipleCollectionLatest, int) MultipleCollectionLatest, initialValue MultipleCollectionLatest) *MultipleCollectionLatestStream { 384 result := MultipleCollectionLatestStreamOf() 385 self.ForEach(func(v MultipleCollectionLatest, i int) { 386 if i == 0 { 387 result.Add(fn(initialValue, v, i)) 388 } else { 389 result.Add(fn(result[i-1], v, i)) 390 } 391 }) 392 *self = result 393 return self 394 } 395 func (self *MultipleCollectionLatestStream) ReduceInterface(fn func(interface{}, MultipleCollectionLatest, int) interface{}) []interface{} { 396 result := []interface{}{} 397 for i, v := range *self { 398 if i == 0 { 399 result = append(result, fn(MultipleCollectionLatest{}, v, i)) 400 } else { 401 result = append(result, fn(result[i-1], v, i)) 402 } 403 } 404 return result 405 } 406 func (self *MultipleCollectionLatestStream) ReduceString(fn func(string, MultipleCollectionLatest, int) string) []string { 407 result := []string{} 408 for i, v := range *self { 409 if i == 0 { 410 result = append(result, fn("", v, i)) 411 } else { 412 result = append(result, fn(result[i-1], v, i)) 413 } 414 } 415 return result 416 } 417 func (self *MultipleCollectionLatestStream) ReduceInt(fn func(int, MultipleCollectionLatest, int) int) []int { 418 result := []int{} 419 for i, v := range *self { 420 if i == 0 { 421 result = append(result, fn(0, v, i)) 422 } else { 423 result = append(result, fn(result[i-1], v, i)) 424 } 425 } 426 return result 427 } 428 func (self *MultipleCollectionLatestStream) ReduceInt32(fn func(int32, MultipleCollectionLatest, int) int32) []int32 { 429 result := []int32{} 430 for i, v := range *self { 431 if i == 0 { 432 result = append(result, fn(0, v, i)) 433 } else { 434 result = append(result, fn(result[i-1], v, i)) 435 } 436 } 437 return result 438 } 439 func (self *MultipleCollectionLatestStream) ReduceInt64(fn func(int64, MultipleCollectionLatest, int) int64) []int64 { 440 result := []int64{} 441 for i, v := range *self { 442 if i == 0 { 443 result = append(result, fn(0, v, i)) 444 } else { 445 result = append(result, fn(result[i-1], v, i)) 446 } 447 } 448 return result 449 } 450 func (self *MultipleCollectionLatestStream) ReduceFloat32(fn func(float32, MultipleCollectionLatest, int) float32) []float32 { 451 result := []float32{} 452 for i, v := range *self { 453 if i == 0 { 454 result = append(result, fn(0.0, v, i)) 455 } else { 456 result = append(result, fn(result[i-1], v, i)) 457 } 458 } 459 return result 460 } 461 func (self *MultipleCollectionLatestStream) ReduceFloat64(fn func(float64, MultipleCollectionLatest, int) float64) []float64 { 462 result := []float64{} 463 for i, v := range *self { 464 if i == 0 { 465 result = append(result, fn(0.0, v, i)) 466 } else { 467 result = append(result, fn(result[i-1], v, i)) 468 } 469 } 470 return result 471 } 472 func (self *MultipleCollectionLatestStream) ReduceBool(fn func(bool, MultipleCollectionLatest, int) bool) []bool { 473 result := []bool{} 474 for i, v := range *self { 475 if i == 0 { 476 result = append(result, fn(false, v, i)) 477 } else { 478 result = append(result, fn(result[i-1], v, i)) 479 } 480 } 481 return result 482 } 483 func (self *MultipleCollectionLatestStream) Reverse() *MultipleCollectionLatestStream { 484 for i, j := 0, self.Len()-1; i < j; i, j = i+1, j-1 { 485 (*self)[i], (*self)[j] = (*self)[j], (*self)[i] 486 } 487 return self 488 } 489 func (self *MultipleCollectionLatestStream) Replace(fn func(MultipleCollectionLatest, int) MultipleCollectionLatest) *MultipleCollectionLatestStream { 490 return self.ForEach(func(v MultipleCollectionLatest, i int) { self.Set(i, fn(v, i)) }) 491 } 492 func (self *MultipleCollectionLatestStream) Select(fn func(MultipleCollectionLatest) interface{}) interface{} { 493 _array := make([]interface{}, 0, len(*self)) 494 for _, v := range *self { 495 _array = append(_array, fn(v)) 496 } 497 return _array 498 } 499 func (self *MultipleCollectionLatestStream) Set(index int, val MultipleCollectionLatest) *MultipleCollectionLatestStream { 500 if len(*self) > index && index >= 0 { 501 (*self)[index] = val 502 } 503 return self 504 } 505 func (self *MultipleCollectionLatestStream) Skip(skip int) *MultipleCollectionLatestStream { 506 return self.Slice(skip, self.Len()-skip) 507 } 508 func (self *MultipleCollectionLatestStream) SkippingEach(fn func(MultipleCollectionLatest, int) int) *MultipleCollectionLatestStream { 509 for i := 0; i < self.Len(); i++ { 510 skip := fn(*self.Get(i), i) 511 i += skip 512 } 513 return self 514 } 515 func (self *MultipleCollectionLatestStream) Slice(startIndex, n int) *MultipleCollectionLatestStream { 516 if last := startIndex + n; len(*self)-1 < startIndex || last < 0 || startIndex < 0 { 517 *self = []MultipleCollectionLatest{} 518 } else if len(*self) < last { 519 *self = (*self)[startIndex:len(*self)] 520 } else { 521 *self = (*self)[startIndex:last] 522 } 523 return self 524 } 525 func (self *MultipleCollectionLatestStream) Sort(fn func(i, j int) bool) *MultipleCollectionLatestStream { 526 sort.SliceStable(*self, fn) 527 return self 528 } 529 530 func (self *MultipleCollectionLatestStream) Tail() *MultipleCollectionLatest { 531 return self.Last() 532 } 533 func (self *MultipleCollectionLatestStream) TailOr(arg MultipleCollectionLatest) MultipleCollectionLatest { 534 return self.LastOr(arg) 535 } 536 func (self *MultipleCollectionLatestStream) ToList() []MultipleCollectionLatest { 537 return self.Val() 538 } 539 func (self *MultipleCollectionLatestStream) Unique() *MultipleCollectionLatestStream { 540 return self.Distinct() 541 } 542 func (self *MultipleCollectionLatestStream) Val() []MultipleCollectionLatest { 543 if self == nil { 544 return []MultipleCollectionLatest{} 545 } 546 return *self.Copy() 547 } 548 func (self *MultipleCollectionLatestStream) While(fn func(MultipleCollectionLatest, int) bool) *MultipleCollectionLatestStream { 549 for i, v := range self.Val() { 550 if !fn(v, i) { 551 break 552 } 553 } 554 return self 555 } 556 func (self *MultipleCollectionLatestStream) Where(fn func(MultipleCollectionLatest) bool) *MultipleCollectionLatestStream { 557 result := MultipleCollectionLatestStreamOf() 558 for _, v := range *self { 559 if fn(v) { 560 result.Add(v) 561 } 562 } 563 *self = result 564 return self 565 } 566 func (self *MultipleCollectionLatestStream) WhereSlim(fn func(MultipleCollectionLatest) bool) *MultipleCollectionLatestStream { 567 result := MultipleCollectionLatestStreamOf() 568 caches := map[string]bool{} 569 for _, v := range *self { 570 key := fmt.Sprintf("%+v", v) 571 if f, ok := caches[key]; ok { 572 if f { 573 result.Add(v) 574 } 575 } else if caches[key] = fn(v); caches[key] { 576 result.Add(v) 577 } 578 } 579 *self = result 580 return self 581 }