github.com/optim-corp/cios-golang-sdk@v0.5.1/cios/stream_resourceownerprofile.go (about) 1 /* 2 * Collection utility of ResourceOwnerProfile 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 ResourceOwnerProfileStream []ResourceOwnerProfile 17 18 func ResourceOwnerProfileStreamOf(arg ...ResourceOwnerProfile) ResourceOwnerProfileStream { 19 return arg 20 } 21 func ResourceOwnerProfileStreamFrom(arg []ResourceOwnerProfile) ResourceOwnerProfileStream { 22 return arg 23 } 24 func CreateResourceOwnerProfileStream(arg ...ResourceOwnerProfile) *ResourceOwnerProfileStream { 25 tmp := ResourceOwnerProfileStreamOf(arg...) 26 return &tmp 27 } 28 func GenerateResourceOwnerProfileStream(arg []ResourceOwnerProfile) *ResourceOwnerProfileStream { 29 tmp := ResourceOwnerProfileStreamFrom(arg) 30 return &tmp 31 } 32 33 func (self *ResourceOwnerProfileStream) Add(arg ResourceOwnerProfile) *ResourceOwnerProfileStream { 34 return self.AddAll(arg) 35 } 36 func (self *ResourceOwnerProfileStream) AddAll(arg ...ResourceOwnerProfile) *ResourceOwnerProfileStream { 37 *self = append(*self, arg...) 38 return self 39 } 40 func (self *ResourceOwnerProfileStream) AddSafe(arg *ResourceOwnerProfile) *ResourceOwnerProfileStream { 41 if arg != nil { 42 self.Add(*arg) 43 } 44 return self 45 } 46 func (self *ResourceOwnerProfileStream) Aggregate(fn func(ResourceOwnerProfile, ResourceOwnerProfile) ResourceOwnerProfile) *ResourceOwnerProfileStream { 47 result := ResourceOwnerProfileStreamOf() 48 self.ForEach(func(v ResourceOwnerProfile, i int) { 49 if i == 0 { 50 result.Add(fn(ResourceOwnerProfile{}, v)) 51 } else { 52 result.Add(fn(result[i-1], v)) 53 } 54 }) 55 *self = result 56 return self 57 } 58 func (self *ResourceOwnerProfileStream) AllMatch(fn func(ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) AnyMatch(fn func(ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) Clone() *ResourceOwnerProfileStream { 75 temp := make([]ResourceOwnerProfile, self.Len()) 76 copy(temp, *self) 77 return (*ResourceOwnerProfileStream)(&temp) 78 } 79 func (self *ResourceOwnerProfileStream) Copy() *ResourceOwnerProfileStream { 80 return self.Clone() 81 } 82 func (self *ResourceOwnerProfileStream) Concat(arg []ResourceOwnerProfile) *ResourceOwnerProfileStream { 83 return self.AddAll(arg...) 84 } 85 func (self *ResourceOwnerProfileStream) Contains(arg ResourceOwnerProfile) bool { 86 return self.FindIndex(func(_arg ResourceOwnerProfile, index int) bool { return reflect.DeepEqual(_arg, arg) }) != -1 87 } 88 func (self *ResourceOwnerProfileStream) Clean() *ResourceOwnerProfileStream { 89 *self = ResourceOwnerProfileStreamOf() 90 return self 91 } 92 func (self *ResourceOwnerProfileStream) Delete(index int) *ResourceOwnerProfileStream { 93 return self.DeleteRange(index, index) 94 } 95 func (self *ResourceOwnerProfileStream) DeleteRange(startIndex, endIndex int) *ResourceOwnerProfileStream { 96 *self = append((*self)[:startIndex], (*self)[endIndex+1:]...) 97 return self 98 } 99 func (self *ResourceOwnerProfileStream) Distinct() *ResourceOwnerProfileStream { 100 caches := map[string]bool{} 101 result := ResourceOwnerProfileStreamOf() 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 *ResourceOwnerProfileStream) Each(fn func(ResourceOwnerProfile)) *ResourceOwnerProfileStream { 117 for _, v := range *self { 118 fn(v) 119 } 120 return self 121 } 122 func (self *ResourceOwnerProfileStream) EachRight(fn func(ResourceOwnerProfile)) *ResourceOwnerProfileStream { 123 for i := self.Len() - 1; i >= 0; i-- { 124 fn(*self.Get(i)) 125 } 126 return self 127 } 128 func (self *ResourceOwnerProfileStream) Equals(arr []ResourceOwnerProfile) 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 *ResourceOwnerProfileStream) Filter(fn func(ResourceOwnerProfile, int) bool) *ResourceOwnerProfileStream { 140 result := ResourceOwnerProfileStreamOf() 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 *ResourceOwnerProfileStream) FilterSlim(fn func(ResourceOwnerProfile, int) bool) *ResourceOwnerProfileStream { 150 result := ResourceOwnerProfileStreamOf() 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 *ResourceOwnerProfileStream) Find(fn func(ResourceOwnerProfile, int) bool) *ResourceOwnerProfile { 167 if i := self.FindIndex(fn); -1 != i { 168 tmp := (*self)[i] 169 return &tmp 170 } 171 return nil 172 } 173 func (self *ResourceOwnerProfileStream) FindOr(fn func(ResourceOwnerProfile, int) bool, or ResourceOwnerProfile) ResourceOwnerProfile { 174 if v := self.Find(fn); v != nil { 175 return *v 176 } 177 return or 178 } 179 func (self *ResourceOwnerProfileStream) FindIndex(fn func(ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) First() *ResourceOwnerProfile { 191 return self.Get(0) 192 } 193 func (self *ResourceOwnerProfileStream) FirstOr(arg ResourceOwnerProfile) ResourceOwnerProfile { 194 if v := self.Get(0); v != nil { 195 return *v 196 } 197 return arg 198 } 199 func (self *ResourceOwnerProfileStream) ForEach(fn func(ResourceOwnerProfile, int)) *ResourceOwnerProfileStream { 200 for i, v := range *self { 201 fn(v, i) 202 } 203 return self 204 } 205 func (self *ResourceOwnerProfileStream) ForEachRight(fn func(ResourceOwnerProfile, int)) *ResourceOwnerProfileStream { 206 for i := self.Len() - 1; i >= 0; i-- { 207 fn(*self.Get(i), i) 208 } 209 return self 210 } 211 func (self *ResourceOwnerProfileStream) GroupBy(fn func(ResourceOwnerProfile, int) string) map[string][]ResourceOwnerProfile { 212 m := map[string][]ResourceOwnerProfile{} 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 *ResourceOwnerProfileStream) GroupByValues(fn func(ResourceOwnerProfile, int) string) [][]ResourceOwnerProfile { 220 var tmp [][]ResourceOwnerProfile 221 for _, v := range self.GroupBy(fn) { 222 tmp = append(tmp, v) 223 } 224 return tmp 225 } 226 func (self *ResourceOwnerProfileStream) IndexOf(arg ResourceOwnerProfile) 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 *ResourceOwnerProfileStream) IsEmpty() bool { 235 return self.Len() == 0 236 } 237 func (self *ResourceOwnerProfileStream) IsPreset() bool { 238 return !self.IsEmpty() 239 } 240 func (self *ResourceOwnerProfileStream) Last() *ResourceOwnerProfile { 241 return self.Get(self.Len() - 1) 242 } 243 func (self *ResourceOwnerProfileStream) LastOr(arg ResourceOwnerProfile) ResourceOwnerProfile { 244 if v := self.Last(); v != nil { 245 return *v 246 } 247 return arg 248 } 249 func (self *ResourceOwnerProfileStream) Len() int { 250 if self == nil { 251 return 0 252 } 253 return len(*self) 254 } 255 func (self *ResourceOwnerProfileStream) Limit(limit int) *ResourceOwnerProfileStream { 256 self.Slice(0, limit) 257 return self 258 } 259 260 func (self *ResourceOwnerProfileStream) Map(fn func(ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) Map2Int(fn func(ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) Map2Int32(fn func(ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) Map2Int64(fn func(ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) Map2Float32(fn func(ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) Map2Float64(fn func(ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) Map2Bool(fn func(ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) Map2Bytes(fn func(ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) Map2String(fn func(ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) Max(fn func(ResourceOwnerProfile, int) float64) *ResourceOwnerProfile { 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 *ResourceOwnerProfileStream) Min(fn func(ResourceOwnerProfile, int) float64) *ResourceOwnerProfile { 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 *ResourceOwnerProfileStream) NoneMatch(fn func(ResourceOwnerProfile, int) bool) bool { 356 return !self.AnyMatch(fn) 357 } 358 func (self *ResourceOwnerProfileStream) Get(index int) *ResourceOwnerProfile { 359 if self.Len() > index && index >= 0 { 360 tmp := (*self)[index] 361 return &tmp 362 } 363 return nil 364 } 365 func (self *ResourceOwnerProfileStream) GetOr(index int, arg ResourceOwnerProfile) ResourceOwnerProfile { 366 if v := self.Get(index); v != nil { 367 return *v 368 } 369 return arg 370 } 371 func (self *ResourceOwnerProfileStream) Peek(fn func(*ResourceOwnerProfile, int)) *ResourceOwnerProfileStream { 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 *ResourceOwnerProfileStream) Reduce(fn func(ResourceOwnerProfile, ResourceOwnerProfile, int) ResourceOwnerProfile) *ResourceOwnerProfileStream { 381 return self.ReduceInit(fn, ResourceOwnerProfile{}) 382 } 383 func (self *ResourceOwnerProfileStream) ReduceInit(fn func(ResourceOwnerProfile, ResourceOwnerProfile, int) ResourceOwnerProfile, initialValue ResourceOwnerProfile) *ResourceOwnerProfileStream { 384 result := ResourceOwnerProfileStreamOf() 385 self.ForEach(func(v ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) ReduceInterface(fn func(interface{}, ResourceOwnerProfile, int) interface{}) []interface{} { 396 result := []interface{}{} 397 for i, v := range *self { 398 if i == 0 { 399 result = append(result, fn(ResourceOwnerProfile{}, v, i)) 400 } else { 401 result = append(result, fn(result[i-1], v, i)) 402 } 403 } 404 return result 405 } 406 func (self *ResourceOwnerProfileStream) ReduceString(fn func(string, ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) ReduceInt(fn func(int, ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) ReduceInt32(fn func(int32, ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) ReduceInt64(fn func(int64, ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) ReduceFloat32(fn func(float32, ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) ReduceFloat64(fn func(float64, ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) ReduceBool(fn func(bool, ResourceOwnerProfile, 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 *ResourceOwnerProfileStream) Reverse() *ResourceOwnerProfileStream { 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 *ResourceOwnerProfileStream) Replace(fn func(ResourceOwnerProfile, int) ResourceOwnerProfile) *ResourceOwnerProfileStream { 490 return self.ForEach(func(v ResourceOwnerProfile, i int) { self.Set(i, fn(v, i)) }) 491 } 492 func (self *ResourceOwnerProfileStream) Select(fn func(ResourceOwnerProfile) 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 *ResourceOwnerProfileStream) Set(index int, val ResourceOwnerProfile) *ResourceOwnerProfileStream { 500 if len(*self) > index && index >= 0 { 501 (*self)[index] = val 502 } 503 return self 504 } 505 func (self *ResourceOwnerProfileStream) Skip(skip int) *ResourceOwnerProfileStream { 506 return self.Slice(skip, self.Len()-skip) 507 } 508 func (self *ResourceOwnerProfileStream) SkippingEach(fn func(ResourceOwnerProfile, int) int) *ResourceOwnerProfileStream { 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 *ResourceOwnerProfileStream) Slice(startIndex, n int) *ResourceOwnerProfileStream { 516 if last := startIndex + n; len(*self)-1 < startIndex || last < 0 || startIndex < 0 { 517 *self = []ResourceOwnerProfile{} 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 *ResourceOwnerProfileStream) Sort(fn func(i, j int) bool) *ResourceOwnerProfileStream { 526 sort.SliceStable(*self, fn) 527 return self 528 } 529 530 func (self *ResourceOwnerProfileStream) Tail() *ResourceOwnerProfile { 531 return self.Last() 532 } 533 func (self *ResourceOwnerProfileStream) TailOr(arg ResourceOwnerProfile) ResourceOwnerProfile { 534 return self.LastOr(arg) 535 } 536 func (self *ResourceOwnerProfileStream) ToList() []ResourceOwnerProfile { 537 return self.Val() 538 } 539 func (self *ResourceOwnerProfileStream) Unique() *ResourceOwnerProfileStream { 540 return self.Distinct() 541 } 542 func (self *ResourceOwnerProfileStream) Val() []ResourceOwnerProfile { 543 if self == nil { 544 return []ResourceOwnerProfile{} 545 } 546 return *self.Copy() 547 } 548 func (self *ResourceOwnerProfileStream) While(fn func(ResourceOwnerProfile, int) bool) *ResourceOwnerProfileStream { 549 for i, v := range self.Val() { 550 if !fn(v, i) { 551 break 552 } 553 } 554 return self 555 } 556 func (self *ResourceOwnerProfileStream) Where(fn func(ResourceOwnerProfile) bool) *ResourceOwnerProfileStream { 557 result := ResourceOwnerProfileStreamOf() 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 *ResourceOwnerProfileStream) WhereSlim(fn func(ResourceOwnerProfile) bool) *ResourceOwnerProfileStream { 567 result := ResourceOwnerProfileStreamOf() 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 }