1package objx 2 3/* 4 Inter (interface{} and []interface{}) 5*/ 6 7// Inter gets the value as a interface{}, returns the optionalDefault 8// value or a system default object if the value is the wrong type. 9func (v *Value) Inter(optionalDefault ...interface{}) interface{} { 10 if s, ok := v.data.(interface{}); ok { 11 return s 12 } 13 if len(optionalDefault) == 1 { 14 return optionalDefault[0] 15 } 16 return nil 17} 18 19// MustInter gets the value as a interface{}. 20// 21// Panics if the object is not a interface{}. 22func (v *Value) MustInter() interface{} { 23 return v.data.(interface{}) 24} 25 26// InterSlice gets the value as a []interface{}, returns the optionalDefault 27// value or nil if the value is not a []interface{}. 28func (v *Value) InterSlice(optionalDefault ...[]interface{}) []interface{} { 29 if s, ok := v.data.([]interface{}); ok { 30 return s 31 } 32 if len(optionalDefault) == 1 { 33 return optionalDefault[0] 34 } 35 return nil 36} 37 38// MustInterSlice gets the value as a []interface{}. 39// 40// Panics if the object is not a []interface{}. 41func (v *Value) MustInterSlice() []interface{} { 42 return v.data.([]interface{}) 43} 44 45// IsInter gets whether the object contained is a interface{} or not. 46func (v *Value) IsInter() bool { 47 _, ok := v.data.(interface{}) 48 return ok 49} 50 51// IsInterSlice gets whether the object contained is a []interface{} or not. 52func (v *Value) IsInterSlice() bool { 53 _, ok := v.data.([]interface{}) 54 return ok 55} 56 57// EachInter calls the specified callback for each object 58// in the []interface{}. 59// 60// Panics if the object is the wrong type. 61func (v *Value) EachInter(callback func(int, interface{}) bool) *Value { 62 for index, val := range v.MustInterSlice() { 63 carryon := callback(index, val) 64 if !carryon { 65 break 66 } 67 } 68 return v 69} 70 71// WhereInter uses the specified decider function to select items 72// from the []interface{}. The object contained in the result will contain 73// only the selected items. 74func (v *Value) WhereInter(decider func(int, interface{}) bool) *Value { 75 var selected []interface{} 76 v.EachInter(func(index int, val interface{}) bool { 77 shouldSelect := decider(index, val) 78 if !shouldSelect { 79 selected = append(selected, val) 80 } 81 return true 82 }) 83 return &Value{data: selected} 84} 85 86// GroupInter uses the specified grouper function to group the items 87// keyed by the return of the grouper. The object contained in the 88// result will contain a map[string][]interface{}. 89func (v *Value) GroupInter(grouper func(int, interface{}) string) *Value { 90 groups := make(map[string][]interface{}) 91 v.EachInter(func(index int, val interface{}) bool { 92 group := grouper(index, val) 93 if _, ok := groups[group]; !ok { 94 groups[group] = make([]interface{}, 0) 95 } 96 groups[group] = append(groups[group], val) 97 return true 98 }) 99 return &Value{data: groups} 100} 101 102// ReplaceInter uses the specified function to replace each interface{}s 103// by iterating each item. The data in the returned result will be a 104// []interface{} containing the replaced items. 105func (v *Value) ReplaceInter(replacer func(int, interface{}) interface{}) *Value { 106 arr := v.MustInterSlice() 107 replaced := make([]interface{}, len(arr)) 108 v.EachInter(func(index int, val interface{}) bool { 109 replaced[index] = replacer(index, val) 110 return true 111 }) 112 return &Value{data: replaced} 113} 114 115// CollectInter uses the specified collector function to collect a value 116// for each of the interface{}s in the slice. The data returned will be a 117// []interface{}. 118func (v *Value) CollectInter(collector func(int, interface{}) interface{}) *Value { 119 arr := v.MustInterSlice() 120 collected := make([]interface{}, len(arr)) 121 v.EachInter(func(index int, val interface{}) bool { 122 collected[index] = collector(index, val) 123 return true 124 }) 125 return &Value{data: collected} 126} 127 128/* 129 MSI (map[string]interface{} and []map[string]interface{}) 130*/ 131 132// MSI gets the value as a map[string]interface{}, returns the optionalDefault 133// value or a system default object if the value is the wrong type. 134func (v *Value) MSI(optionalDefault ...map[string]interface{}) map[string]interface{} { 135 if s, ok := v.data.(map[string]interface{}); ok { 136 return s 137 } 138 if len(optionalDefault) == 1 { 139 return optionalDefault[0] 140 } 141 return nil 142} 143 144// MustMSI gets the value as a map[string]interface{}. 145// 146// Panics if the object is not a map[string]interface{}. 147func (v *Value) MustMSI() map[string]interface{} { 148 return v.data.(map[string]interface{}) 149} 150 151// MSISlice gets the value as a []map[string]interface{}, returns the optionalDefault 152// value or nil if the value is not a []map[string]interface{}. 153func (v *Value) MSISlice(optionalDefault ...[]map[string]interface{}) []map[string]interface{} { 154 if s, ok := v.data.([]map[string]interface{}); ok { 155 return s 156 } 157 if len(optionalDefault) == 1 { 158 return optionalDefault[0] 159 } 160 return nil 161} 162 163// MustMSISlice gets the value as a []map[string]interface{}. 164// 165// Panics if the object is not a []map[string]interface{}. 166func (v *Value) MustMSISlice() []map[string]interface{} { 167 return v.data.([]map[string]interface{}) 168} 169 170// IsMSI gets whether the object contained is a map[string]interface{} or not. 171func (v *Value) IsMSI() bool { 172 _, ok := v.data.(map[string]interface{}) 173 return ok 174} 175 176// IsMSISlice gets whether the object contained is a []map[string]interface{} or not. 177func (v *Value) IsMSISlice() bool { 178 _, ok := v.data.([]map[string]interface{}) 179 return ok 180} 181 182// EachMSI calls the specified callback for each object 183// in the []map[string]interface{}. 184// 185// Panics if the object is the wrong type. 186func (v *Value) EachMSI(callback func(int, map[string]interface{}) bool) *Value { 187 for index, val := range v.MustMSISlice() { 188 carryon := callback(index, val) 189 if !carryon { 190 break 191 } 192 } 193 return v 194} 195 196// WhereMSI uses the specified decider function to select items 197// from the []map[string]interface{}. The object contained in the result will contain 198// only the selected items. 199func (v *Value) WhereMSI(decider func(int, map[string]interface{}) bool) *Value { 200 var selected []map[string]interface{} 201 v.EachMSI(func(index int, val map[string]interface{}) bool { 202 shouldSelect := decider(index, val) 203 if !shouldSelect { 204 selected = append(selected, val) 205 } 206 return true 207 }) 208 return &Value{data: selected} 209} 210 211// GroupMSI uses the specified grouper function to group the items 212// keyed by the return of the grouper. The object contained in the 213// result will contain a map[string][]map[string]interface{}. 214func (v *Value) GroupMSI(grouper func(int, map[string]interface{}) string) *Value { 215 groups := make(map[string][]map[string]interface{}) 216 v.EachMSI(func(index int, val map[string]interface{}) bool { 217 group := grouper(index, val) 218 if _, ok := groups[group]; !ok { 219 groups[group] = make([]map[string]interface{}, 0) 220 } 221 groups[group] = append(groups[group], val) 222 return true 223 }) 224 return &Value{data: groups} 225} 226 227// ReplaceMSI uses the specified function to replace each map[string]interface{}s 228// by iterating each item. The data in the returned result will be a 229// []map[string]interface{} containing the replaced items. 230func (v *Value) ReplaceMSI(replacer func(int, map[string]interface{}) map[string]interface{}) *Value { 231 arr := v.MustMSISlice() 232 replaced := make([]map[string]interface{}, len(arr)) 233 v.EachMSI(func(index int, val map[string]interface{}) bool { 234 replaced[index] = replacer(index, val) 235 return true 236 }) 237 return &Value{data: replaced} 238} 239 240// CollectMSI uses the specified collector function to collect a value 241// for each of the map[string]interface{}s in the slice. The data returned will be a 242// []interface{}. 243func (v *Value) CollectMSI(collector func(int, map[string]interface{}) interface{}) *Value { 244 arr := v.MustMSISlice() 245 collected := make([]interface{}, len(arr)) 246 v.EachMSI(func(index int, val map[string]interface{}) bool { 247 collected[index] = collector(index, val) 248 return true 249 }) 250 return &Value{data: collected} 251} 252 253/* 254 ObjxMap ((Map) and [](Map)) 255*/ 256 257// ObjxMap gets the value as a (Map), returns the optionalDefault 258// value or a system default object if the value is the wrong type. 259func (v *Value) ObjxMap(optionalDefault ...(Map)) Map { 260 if s, ok := v.data.((Map)); ok { 261 return s 262 } 263 if len(optionalDefault) == 1 { 264 return optionalDefault[0] 265 } 266 return New(nil) 267} 268 269// MustObjxMap gets the value as a (Map). 270// 271// Panics if the object is not a (Map). 272func (v *Value) MustObjxMap() Map { 273 return v.data.((Map)) 274} 275 276// ObjxMapSlice gets the value as a [](Map), returns the optionalDefault 277// value or nil if the value is not a [](Map). 278func (v *Value) ObjxMapSlice(optionalDefault ...[](Map)) [](Map) { 279 if s, ok := v.data.([](Map)); ok { 280 return s 281 } 282 if len(optionalDefault) == 1 { 283 return optionalDefault[0] 284 } 285 return nil 286} 287 288// MustObjxMapSlice gets the value as a [](Map). 289// 290// Panics if the object is not a [](Map). 291func (v *Value) MustObjxMapSlice() [](Map) { 292 return v.data.([](Map)) 293} 294 295// IsObjxMap gets whether the object contained is a (Map) or not. 296func (v *Value) IsObjxMap() bool { 297 _, ok := v.data.((Map)) 298 return ok 299} 300 301// IsObjxMapSlice gets whether the object contained is a [](Map) or not. 302func (v *Value) IsObjxMapSlice() bool { 303 _, ok := v.data.([](Map)) 304 return ok 305} 306 307// EachObjxMap calls the specified callback for each object 308// in the [](Map). 309// 310// Panics if the object is the wrong type. 311func (v *Value) EachObjxMap(callback func(int, Map) bool) *Value { 312 for index, val := range v.MustObjxMapSlice() { 313 carryon := callback(index, val) 314 if !carryon { 315 break 316 } 317 } 318 return v 319} 320 321// WhereObjxMap uses the specified decider function to select items 322// from the [](Map). The object contained in the result will contain 323// only the selected items. 324func (v *Value) WhereObjxMap(decider func(int, Map) bool) *Value { 325 var selected [](Map) 326 v.EachObjxMap(func(index int, val Map) bool { 327 shouldSelect := decider(index, val) 328 if !shouldSelect { 329 selected = append(selected, val) 330 } 331 return true 332 }) 333 return &Value{data: selected} 334} 335 336// GroupObjxMap uses the specified grouper function to group the items 337// keyed by the return of the grouper. The object contained in the 338// result will contain a map[string][](Map). 339func (v *Value) GroupObjxMap(grouper func(int, Map) string) *Value { 340 groups := make(map[string][](Map)) 341 v.EachObjxMap(func(index int, val Map) bool { 342 group := grouper(index, val) 343 if _, ok := groups[group]; !ok { 344 groups[group] = make([](Map), 0) 345 } 346 groups[group] = append(groups[group], val) 347 return true 348 }) 349 return &Value{data: groups} 350} 351 352// ReplaceObjxMap uses the specified function to replace each (Map)s 353// by iterating each item. The data in the returned result will be a 354// [](Map) containing the replaced items. 355func (v *Value) ReplaceObjxMap(replacer func(int, Map) Map) *Value { 356 arr := v.MustObjxMapSlice() 357 replaced := make([](Map), len(arr)) 358 v.EachObjxMap(func(index int, val Map) bool { 359 replaced[index] = replacer(index, val) 360 return true 361 }) 362 return &Value{data: replaced} 363} 364 365// CollectObjxMap uses the specified collector function to collect a value 366// for each of the (Map)s in the slice. The data returned will be a 367// []interface{}. 368func (v *Value) CollectObjxMap(collector func(int, Map) interface{}) *Value { 369 arr := v.MustObjxMapSlice() 370 collected := make([]interface{}, len(arr)) 371 v.EachObjxMap(func(index int, val Map) bool { 372 collected[index] = collector(index, val) 373 return true 374 }) 375 return &Value{data: collected} 376} 377 378/* 379 Bool (bool and []bool) 380*/ 381 382// Bool gets the value as a bool, returns the optionalDefault 383// value or a system default object if the value is the wrong type. 384func (v *Value) Bool(optionalDefault ...bool) bool { 385 if s, ok := v.data.(bool); ok { 386 return s 387 } 388 if len(optionalDefault) == 1 { 389 return optionalDefault[0] 390 } 391 return false 392} 393 394// MustBool gets the value as a bool. 395// 396// Panics if the object is not a bool. 397func (v *Value) MustBool() bool { 398 return v.data.(bool) 399} 400 401// BoolSlice gets the value as a []bool, returns the optionalDefault 402// value or nil if the value is not a []bool. 403func (v *Value) BoolSlice(optionalDefault ...[]bool) []bool { 404 if s, ok := v.data.([]bool); ok { 405 return s 406 } 407 if len(optionalDefault) == 1 { 408 return optionalDefault[0] 409 } 410 return nil 411} 412 413// MustBoolSlice gets the value as a []bool. 414// 415// Panics if the object is not a []bool. 416func (v *Value) MustBoolSlice() []bool { 417 return v.data.([]bool) 418} 419 420// IsBool gets whether the object contained is a bool or not. 421func (v *Value) IsBool() bool { 422 _, ok := v.data.(bool) 423 return ok 424} 425 426// IsBoolSlice gets whether the object contained is a []bool or not. 427func (v *Value) IsBoolSlice() bool { 428 _, ok := v.data.([]bool) 429 return ok 430} 431 432// EachBool calls the specified callback for each object 433// in the []bool. 434// 435// Panics if the object is the wrong type. 436func (v *Value) EachBool(callback func(int, bool) bool) *Value { 437 for index, val := range v.MustBoolSlice() { 438 carryon := callback(index, val) 439 if !carryon { 440 break 441 } 442 } 443 return v 444} 445 446// WhereBool uses the specified decider function to select items 447// from the []bool. The object contained in the result will contain 448// only the selected items. 449func (v *Value) WhereBool(decider func(int, bool) bool) *Value { 450 var selected []bool 451 v.EachBool(func(index int, val bool) bool { 452 shouldSelect := decider(index, val) 453 if !shouldSelect { 454 selected = append(selected, val) 455 } 456 return true 457 }) 458 return &Value{data: selected} 459} 460 461// GroupBool uses the specified grouper function to group the items 462// keyed by the return of the grouper. The object contained in the 463// result will contain a map[string][]bool. 464func (v *Value) GroupBool(grouper func(int, bool) string) *Value { 465 groups := make(map[string][]bool) 466 v.EachBool(func(index int, val bool) bool { 467 group := grouper(index, val) 468 if _, ok := groups[group]; !ok { 469 groups[group] = make([]bool, 0) 470 } 471 groups[group] = append(groups[group], val) 472 return true 473 }) 474 return &Value{data: groups} 475} 476 477// ReplaceBool uses the specified function to replace each bools 478// by iterating each item. The data in the returned result will be a 479// []bool containing the replaced items. 480func (v *Value) ReplaceBool(replacer func(int, bool) bool) *Value { 481 arr := v.MustBoolSlice() 482 replaced := make([]bool, len(arr)) 483 v.EachBool(func(index int, val bool) bool { 484 replaced[index] = replacer(index, val) 485 return true 486 }) 487 return &Value{data: replaced} 488} 489 490// CollectBool uses the specified collector function to collect a value 491// for each of the bools in the slice. The data returned will be a 492// []interface{}. 493func (v *Value) CollectBool(collector func(int, bool) interface{}) *Value { 494 arr := v.MustBoolSlice() 495 collected := make([]interface{}, len(arr)) 496 v.EachBool(func(index int, val bool) bool { 497 collected[index] = collector(index, val) 498 return true 499 }) 500 return &Value{data: collected} 501} 502 503/* 504 Str (string and []string) 505*/ 506 507// Str gets the value as a string, returns the optionalDefault 508// value or a system default object if the value is the wrong type. 509func (v *Value) Str(optionalDefault ...string) string { 510 if s, ok := v.data.(string); ok { 511 return s 512 } 513 if len(optionalDefault) == 1 { 514 return optionalDefault[0] 515 } 516 return "" 517} 518 519// MustStr gets the value as a string. 520// 521// Panics if the object is not a string. 522func (v *Value) MustStr() string { 523 return v.data.(string) 524} 525 526// StrSlice gets the value as a []string, returns the optionalDefault 527// value or nil if the value is not a []string. 528func (v *Value) StrSlice(optionalDefault ...[]string) []string { 529 if s, ok := v.data.([]string); ok { 530 return s 531 } 532 if len(optionalDefault) == 1 { 533 return optionalDefault[0] 534 } 535 return nil 536} 537 538// MustStrSlice gets the value as a []string. 539// 540// Panics if the object is not a []string. 541func (v *Value) MustStrSlice() []string { 542 return v.data.([]string) 543} 544 545// IsStr gets whether the object contained is a string or not. 546func (v *Value) IsStr() bool { 547 _, ok := v.data.(string) 548 return ok 549} 550 551// IsStrSlice gets whether the object contained is a []string or not. 552func (v *Value) IsStrSlice() bool { 553 _, ok := v.data.([]string) 554 return ok 555} 556 557// EachStr calls the specified callback for each object 558// in the []string. 559// 560// Panics if the object is the wrong type. 561func (v *Value) EachStr(callback func(int, string) bool) *Value { 562 for index, val := range v.MustStrSlice() { 563 carryon := callback(index, val) 564 if !carryon { 565 break 566 } 567 } 568 return v 569} 570 571// WhereStr uses the specified decider function to select items 572// from the []string. The object contained in the result will contain 573// only the selected items. 574func (v *Value) WhereStr(decider func(int, string) bool) *Value { 575 var selected []string 576 v.EachStr(func(index int, val string) bool { 577 shouldSelect := decider(index, val) 578 if !shouldSelect { 579 selected = append(selected, val) 580 } 581 return true 582 }) 583 return &Value{data: selected} 584} 585 586// GroupStr uses the specified grouper function to group the items 587// keyed by the return of the grouper. The object contained in the 588// result will contain a map[string][]string. 589func (v *Value) GroupStr(grouper func(int, string) string) *Value { 590 groups := make(map[string][]string) 591 v.EachStr(func(index int, val string) bool { 592 group := grouper(index, val) 593 if _, ok := groups[group]; !ok { 594 groups[group] = make([]string, 0) 595 } 596 groups[group] = append(groups[group], val) 597 return true 598 }) 599 return &Value{data: groups} 600} 601 602// ReplaceStr uses the specified function to replace each strings 603// by iterating each item. The data in the returned result will be a 604// []string containing the replaced items. 605func (v *Value) ReplaceStr(replacer func(int, string) string) *Value { 606 arr := v.MustStrSlice() 607 replaced := make([]string, len(arr)) 608 v.EachStr(func(index int, val string) bool { 609 replaced[index] = replacer(index, val) 610 return true 611 }) 612 return &Value{data: replaced} 613} 614 615// CollectStr uses the specified collector function to collect a value 616// for each of the strings in the slice. The data returned will be a 617// []interface{}. 618func (v *Value) CollectStr(collector func(int, string) interface{}) *Value { 619 arr := v.MustStrSlice() 620 collected := make([]interface{}, len(arr)) 621 v.EachStr(func(index int, val string) bool { 622 collected[index] = collector(index, val) 623 return true 624 }) 625 return &Value{data: collected} 626} 627 628/* 629 Int (int and []int) 630*/ 631 632// Int gets the value as a int, returns the optionalDefault 633// value or a system default object if the value is the wrong type. 634func (v *Value) Int(optionalDefault ...int) int { 635 if s, ok := v.data.(int); ok { 636 return s 637 } 638 if len(optionalDefault) == 1 { 639 return optionalDefault[0] 640 } 641 return 0 642} 643 644// MustInt gets the value as a int. 645// 646// Panics if the object is not a int. 647func (v *Value) MustInt() int { 648 return v.data.(int) 649} 650 651// IntSlice gets the value as a []int, returns the optionalDefault 652// value or nil if the value is not a []int. 653func (v *Value) IntSlice(optionalDefault ...[]int) []int { 654 if s, ok := v.data.([]int); ok { 655 return s 656 } 657 if len(optionalDefault) == 1 { 658 return optionalDefault[0] 659 } 660 return nil 661} 662 663// MustIntSlice gets the value as a []int. 664// 665// Panics if the object is not a []int. 666func (v *Value) MustIntSlice() []int { 667 return v.data.([]int) 668} 669 670// IsInt gets whether the object contained is a int or not. 671func (v *Value) IsInt() bool { 672 _, ok := v.data.(int) 673 return ok 674} 675 676// IsIntSlice gets whether the object contained is a []int or not. 677func (v *Value) IsIntSlice() bool { 678 _, ok := v.data.([]int) 679 return ok 680} 681 682// EachInt calls the specified callback for each object 683// in the []int. 684// 685// Panics if the object is the wrong type. 686func (v *Value) EachInt(callback func(int, int) bool) *Value { 687 for index, val := range v.MustIntSlice() { 688 carryon := callback(index, val) 689 if !carryon { 690 break 691 } 692 } 693 return v 694} 695 696// WhereInt uses the specified decider function to select items 697// from the []int. The object contained in the result will contain 698// only the selected items. 699func (v *Value) WhereInt(decider func(int, int) bool) *Value { 700 var selected []int 701 v.EachInt(func(index int, val int) bool { 702 shouldSelect := decider(index, val) 703 if !shouldSelect { 704 selected = append(selected, val) 705 } 706 return true 707 }) 708 return &Value{data: selected} 709} 710 711// GroupInt uses the specified grouper function to group the items 712// keyed by the return of the grouper. The object contained in the 713// result will contain a map[string][]int. 714func (v *Value) GroupInt(grouper func(int, int) string) *Value { 715 groups := make(map[string][]int) 716 v.EachInt(func(index int, val int) bool { 717 group := grouper(index, val) 718 if _, ok := groups[group]; !ok { 719 groups[group] = make([]int, 0) 720 } 721 groups[group] = append(groups[group], val) 722 return true 723 }) 724 return &Value{data: groups} 725} 726 727// ReplaceInt uses the specified function to replace each ints 728// by iterating each item. The data in the returned result will be a 729// []int containing the replaced items. 730func (v *Value) ReplaceInt(replacer func(int, int) int) *Value { 731 arr := v.MustIntSlice() 732 replaced := make([]int, len(arr)) 733 v.EachInt(func(index int, val int) bool { 734 replaced[index] = replacer(index, val) 735 return true 736 }) 737 return &Value{data: replaced} 738} 739 740// CollectInt uses the specified collector function to collect a value 741// for each of the ints in the slice. The data returned will be a 742// []interface{}. 743func (v *Value) CollectInt(collector func(int, int) interface{}) *Value { 744 arr := v.MustIntSlice() 745 collected := make([]interface{}, len(arr)) 746 v.EachInt(func(index int, val int) bool { 747 collected[index] = collector(index, val) 748 return true 749 }) 750 return &Value{data: collected} 751} 752 753/* 754 Int8 (int8 and []int8) 755*/ 756 757// Int8 gets the value as a int8, returns the optionalDefault 758// value or a system default object if the value is the wrong type. 759func (v *Value) Int8(optionalDefault ...int8) int8 { 760 if s, ok := v.data.(int8); ok { 761 return s 762 } 763 if len(optionalDefault) == 1 { 764 return optionalDefault[0] 765 } 766 return 0 767} 768 769// MustInt8 gets the value as a int8. 770// 771// Panics if the object is not a int8. 772func (v *Value) MustInt8() int8 { 773 return v.data.(int8) 774} 775 776// Int8Slice gets the value as a []int8, returns the optionalDefault 777// value or nil if the value is not a []int8. 778func (v *Value) Int8Slice(optionalDefault ...[]int8) []int8 { 779 if s, ok := v.data.([]int8); ok { 780 return s 781 } 782 if len(optionalDefault) == 1 { 783 return optionalDefault[0] 784 } 785 return nil 786} 787 788// MustInt8Slice gets the value as a []int8. 789// 790// Panics if the object is not a []int8. 791func (v *Value) MustInt8Slice() []int8 { 792 return v.data.([]int8) 793} 794 795// IsInt8 gets whether the object contained is a int8 or not. 796func (v *Value) IsInt8() bool { 797 _, ok := v.data.(int8) 798 return ok 799} 800 801// IsInt8Slice gets whether the object contained is a []int8 or not. 802func (v *Value) IsInt8Slice() bool { 803 _, ok := v.data.([]int8) 804 return ok 805} 806 807// EachInt8 calls the specified callback for each object 808// in the []int8. 809// 810// Panics if the object is the wrong type. 811func (v *Value) EachInt8(callback func(int, int8) bool) *Value { 812 for index, val := range v.MustInt8Slice() { 813 carryon := callback(index, val) 814 if !carryon { 815 break 816 } 817 } 818 return v 819} 820 821// WhereInt8 uses the specified decider function to select items 822// from the []int8. The object contained in the result will contain 823// only the selected items. 824func (v *Value) WhereInt8(decider func(int, int8) bool) *Value { 825 var selected []int8 826 v.EachInt8(func(index int, val int8) bool { 827 shouldSelect := decider(index, val) 828 if !shouldSelect { 829 selected = append(selected, val) 830 } 831 return true 832 }) 833 return &Value{data: selected} 834} 835 836// GroupInt8 uses the specified grouper function to group the items 837// keyed by the return of the grouper. The object contained in the 838// result will contain a map[string][]int8. 839func (v *Value) GroupInt8(grouper func(int, int8) string) *Value { 840 groups := make(map[string][]int8) 841 v.EachInt8(func(index int, val int8) bool { 842 group := grouper(index, val) 843 if _, ok := groups[group]; !ok { 844 groups[group] = make([]int8, 0) 845 } 846 groups[group] = append(groups[group], val) 847 return true 848 }) 849 return &Value{data: groups} 850} 851 852// ReplaceInt8 uses the specified function to replace each int8s 853// by iterating each item. The data in the returned result will be a 854// []int8 containing the replaced items. 855func (v *Value) ReplaceInt8(replacer func(int, int8) int8) *Value { 856 arr := v.MustInt8Slice() 857 replaced := make([]int8, len(arr)) 858 v.EachInt8(func(index int, val int8) bool { 859 replaced[index] = replacer(index, val) 860 return true 861 }) 862 return &Value{data: replaced} 863} 864 865// CollectInt8 uses the specified collector function to collect a value 866// for each of the int8s in the slice. The data returned will be a 867// []interface{}. 868func (v *Value) CollectInt8(collector func(int, int8) interface{}) *Value { 869 arr := v.MustInt8Slice() 870 collected := make([]interface{}, len(arr)) 871 v.EachInt8(func(index int, val int8) bool { 872 collected[index] = collector(index, val) 873 return true 874 }) 875 return &Value{data: collected} 876} 877 878/* 879 Int16 (int16 and []int16) 880*/ 881 882// Int16 gets the value as a int16, returns the optionalDefault 883// value or a system default object if the value is the wrong type. 884func (v *Value) Int16(optionalDefault ...int16) int16 { 885 if s, ok := v.data.(int16); ok { 886 return s 887 } 888 if len(optionalDefault) == 1 { 889 return optionalDefault[0] 890 } 891 return 0 892} 893 894// MustInt16 gets the value as a int16. 895// 896// Panics if the object is not a int16. 897func (v *Value) MustInt16() int16 { 898 return v.data.(int16) 899} 900 901// Int16Slice gets the value as a []int16, returns the optionalDefault 902// value or nil if the value is not a []int16. 903func (v *Value) Int16Slice(optionalDefault ...[]int16) []int16 { 904 if s, ok := v.data.([]int16); ok { 905 return s 906 } 907 if len(optionalDefault) == 1 { 908 return optionalDefault[0] 909 } 910 return nil 911} 912 913// MustInt16Slice gets the value as a []int16. 914// 915// Panics if the object is not a []int16. 916func (v *Value) MustInt16Slice() []int16 { 917 return v.data.([]int16) 918} 919 920// IsInt16 gets whether the object contained is a int16 or not. 921func (v *Value) IsInt16() bool { 922 _, ok := v.data.(int16) 923 return ok 924} 925 926// IsInt16Slice gets whether the object contained is a []int16 or not. 927func (v *Value) IsInt16Slice() bool { 928 _, ok := v.data.([]int16) 929 return ok 930} 931 932// EachInt16 calls the specified callback for each object 933// in the []int16. 934// 935// Panics if the object is the wrong type. 936func (v *Value) EachInt16(callback func(int, int16) bool) *Value { 937 for index, val := range v.MustInt16Slice() { 938 carryon := callback(index, val) 939 if !carryon { 940 break 941 } 942 } 943 return v 944} 945 946// WhereInt16 uses the specified decider function to select items 947// from the []int16. The object contained in the result will contain 948// only the selected items. 949func (v *Value) WhereInt16(decider func(int, int16) bool) *Value { 950 var selected []int16 951 v.EachInt16(func(index int, val int16) bool { 952 shouldSelect := decider(index, val) 953 if !shouldSelect { 954 selected = append(selected, val) 955 } 956 return true 957 }) 958 return &Value{data: selected} 959} 960 961// GroupInt16 uses the specified grouper function to group the items 962// keyed by the return of the grouper. The object contained in the 963// result will contain a map[string][]int16. 964func (v *Value) GroupInt16(grouper func(int, int16) string) *Value { 965 groups := make(map[string][]int16) 966 v.EachInt16(func(index int, val int16) bool { 967 group := grouper(index, val) 968 if _, ok := groups[group]; !ok { 969 groups[group] = make([]int16, 0) 970 } 971 groups[group] = append(groups[group], val) 972 return true 973 }) 974 return &Value{data: groups} 975} 976 977// ReplaceInt16 uses the specified function to replace each int16s 978// by iterating each item. The data in the returned result will be a 979// []int16 containing the replaced items. 980func (v *Value) ReplaceInt16(replacer func(int, int16) int16) *Value { 981 arr := v.MustInt16Slice() 982 replaced := make([]int16, len(arr)) 983 v.EachInt16(func(index int, val int16) bool { 984 replaced[index] = replacer(index, val) 985 return true 986 }) 987 return &Value{data: replaced} 988} 989 990// CollectInt16 uses the specified collector function to collect a value 991// for each of the int16s in the slice. The data returned will be a 992// []interface{}. 993func (v *Value) CollectInt16(collector func(int, int16) interface{}) *Value { 994 arr := v.MustInt16Slice() 995 collected := make([]interface{}, len(arr)) 996 v.EachInt16(func(index int, val int16) bool { 997 collected[index] = collector(index, val) 998 return true 999 }) 1000 return &Value{data: collected} 1001} 1002 1003/* 1004 Int32 (int32 and []int32) 1005*/ 1006 1007// Int32 gets the value as a int32, returns the optionalDefault 1008// value or a system default object if the value is the wrong type. 1009func (v *Value) Int32(optionalDefault ...int32) int32 { 1010 if s, ok := v.data.(int32); ok { 1011 return s 1012 } 1013 if len(optionalDefault) == 1 { 1014 return optionalDefault[0] 1015 } 1016 return 0 1017} 1018 1019// MustInt32 gets the value as a int32. 1020// 1021// Panics if the object is not a int32. 1022func (v *Value) MustInt32() int32 { 1023 return v.data.(int32) 1024} 1025 1026// Int32Slice gets the value as a []int32, returns the optionalDefault 1027// value or nil if the value is not a []int32. 1028func (v *Value) Int32Slice(optionalDefault ...[]int32) []int32 { 1029 if s, ok := v.data.([]int32); ok { 1030 return s 1031 } 1032 if len(optionalDefault) == 1 { 1033 return optionalDefault[0] 1034 } 1035 return nil 1036} 1037 1038// MustInt32Slice gets the value as a []int32. 1039// 1040// Panics if the object is not a []int32. 1041func (v *Value) MustInt32Slice() []int32 { 1042 return v.data.([]int32) 1043} 1044 1045// IsInt32 gets whether the object contained is a int32 or not. 1046func (v *Value) IsInt32() bool { 1047 _, ok := v.data.(int32) 1048 return ok 1049} 1050 1051// IsInt32Slice gets whether the object contained is a []int32 or not. 1052func (v *Value) IsInt32Slice() bool { 1053 _, ok := v.data.([]int32) 1054 return ok 1055} 1056 1057// EachInt32 calls the specified callback for each object 1058// in the []int32. 1059// 1060// Panics if the object is the wrong type. 1061func (v *Value) EachInt32(callback func(int, int32) bool) *Value { 1062 for index, val := range v.MustInt32Slice() { 1063 carryon := callback(index, val) 1064 if !carryon { 1065 break 1066 } 1067 } 1068 return v 1069} 1070 1071// WhereInt32 uses the specified decider function to select items 1072// from the []int32. The object contained in the result will contain 1073// only the selected items. 1074func (v *Value) WhereInt32(decider func(int, int32) bool) *Value { 1075 var selected []int32 1076 v.EachInt32(func(index int, val int32) bool { 1077 shouldSelect := decider(index, val) 1078 if !shouldSelect { 1079 selected = append(selected, val) 1080 } 1081 return true 1082 }) 1083 return &Value{data: selected} 1084} 1085 1086// GroupInt32 uses the specified grouper function to group the items 1087// keyed by the return of the grouper. The object contained in the 1088// result will contain a map[string][]int32. 1089func (v *Value) GroupInt32(grouper func(int, int32) string) *Value { 1090 groups := make(map[string][]int32) 1091 v.EachInt32(func(index int, val int32) bool { 1092 group := grouper(index, val) 1093 if _, ok := groups[group]; !ok { 1094 groups[group] = make([]int32, 0) 1095 } 1096 groups[group] = append(groups[group], val) 1097 return true 1098 }) 1099 return &Value{data: groups} 1100} 1101 1102// ReplaceInt32 uses the specified function to replace each int32s 1103// by iterating each item. The data in the returned result will be a 1104// []int32 containing the replaced items. 1105func (v *Value) ReplaceInt32(replacer func(int, int32) int32) *Value { 1106 arr := v.MustInt32Slice() 1107 replaced := make([]int32, len(arr)) 1108 v.EachInt32(func(index int, val int32) bool { 1109 replaced[index] = replacer(index, val) 1110 return true 1111 }) 1112 return &Value{data: replaced} 1113} 1114 1115// CollectInt32 uses the specified collector function to collect a value 1116// for each of the int32s in the slice. The data returned will be a 1117// []interface{}. 1118func (v *Value) CollectInt32(collector func(int, int32) interface{}) *Value { 1119 arr := v.MustInt32Slice() 1120 collected := make([]interface{}, len(arr)) 1121 v.EachInt32(func(index int, val int32) bool { 1122 collected[index] = collector(index, val) 1123 return true 1124 }) 1125 return &Value{data: collected} 1126} 1127 1128/* 1129 Int64 (int64 and []int64) 1130*/ 1131 1132// Int64 gets the value as a int64, returns the optionalDefault 1133// value or a system default object if the value is the wrong type. 1134func (v *Value) Int64(optionalDefault ...int64) int64 { 1135 if s, ok := v.data.(int64); ok { 1136 return s 1137 } 1138 if len(optionalDefault) == 1 { 1139 return optionalDefault[0] 1140 } 1141 return 0 1142} 1143 1144// MustInt64 gets the value as a int64. 1145// 1146// Panics if the object is not a int64. 1147func (v *Value) MustInt64() int64 { 1148 return v.data.(int64) 1149} 1150 1151// Int64Slice gets the value as a []int64, returns the optionalDefault 1152// value or nil if the value is not a []int64. 1153func (v *Value) Int64Slice(optionalDefault ...[]int64) []int64 { 1154 if s, ok := v.data.([]int64); ok { 1155 return s 1156 } 1157 if len(optionalDefault) == 1 { 1158 return optionalDefault[0] 1159 } 1160 return nil 1161} 1162 1163// MustInt64Slice gets the value as a []int64. 1164// 1165// Panics if the object is not a []int64. 1166func (v *Value) MustInt64Slice() []int64 { 1167 return v.data.([]int64) 1168} 1169 1170// IsInt64 gets whether the object contained is a int64 or not. 1171func (v *Value) IsInt64() bool { 1172 _, ok := v.data.(int64) 1173 return ok 1174} 1175 1176// IsInt64Slice gets whether the object contained is a []int64 or not. 1177func (v *Value) IsInt64Slice() bool { 1178 _, ok := v.data.([]int64) 1179 return ok 1180} 1181 1182// EachInt64 calls the specified callback for each object 1183// in the []int64. 1184// 1185// Panics if the object is the wrong type. 1186func (v *Value) EachInt64(callback func(int, int64) bool) *Value { 1187 for index, val := range v.MustInt64Slice() { 1188 carryon := callback(index, val) 1189 if !carryon { 1190 break 1191 } 1192 } 1193 return v 1194} 1195 1196// WhereInt64 uses the specified decider function to select items 1197// from the []int64. The object contained in the result will contain 1198// only the selected items. 1199func (v *Value) WhereInt64(decider func(int, int64) bool) *Value { 1200 var selected []int64 1201 v.EachInt64(func(index int, val int64) bool { 1202 shouldSelect := decider(index, val) 1203 if !shouldSelect { 1204 selected = append(selected, val) 1205 } 1206 return true 1207 }) 1208 return &Value{data: selected} 1209} 1210 1211// GroupInt64 uses the specified grouper function to group the items 1212// keyed by the return of the grouper. The object contained in the 1213// result will contain a map[string][]int64. 1214func (v *Value) GroupInt64(grouper func(int, int64) string) *Value { 1215 groups := make(map[string][]int64) 1216 v.EachInt64(func(index int, val int64) bool { 1217 group := grouper(index, val) 1218 if _, ok := groups[group]; !ok { 1219 groups[group] = make([]int64, 0) 1220 } 1221 groups[group] = append(groups[group], val) 1222 return true 1223 }) 1224 return &Value{data: groups} 1225} 1226 1227// ReplaceInt64 uses the specified function to replace each int64s 1228// by iterating each item. The data in the returned result will be a 1229// []int64 containing the replaced items. 1230func (v *Value) ReplaceInt64(replacer func(int, int64) int64) *Value { 1231 arr := v.MustInt64Slice() 1232 replaced := make([]int64, len(arr)) 1233 v.EachInt64(func(index int, val int64) bool { 1234 replaced[index] = replacer(index, val) 1235 return true 1236 }) 1237 return &Value{data: replaced} 1238} 1239 1240// CollectInt64 uses the specified collector function to collect a value 1241// for each of the int64s in the slice. The data returned will be a 1242// []interface{}. 1243func (v *Value) CollectInt64(collector func(int, int64) interface{}) *Value { 1244 arr := v.MustInt64Slice() 1245 collected := make([]interface{}, len(arr)) 1246 v.EachInt64(func(index int, val int64) bool { 1247 collected[index] = collector(index, val) 1248 return true 1249 }) 1250 return &Value{data: collected} 1251} 1252 1253/* 1254 Uint (uint and []uint) 1255*/ 1256 1257// Uint gets the value as a uint, returns the optionalDefault 1258// value or a system default object if the value is the wrong type. 1259func (v *Value) Uint(optionalDefault ...uint) uint { 1260 if s, ok := v.data.(uint); ok { 1261 return s 1262 } 1263 if len(optionalDefault) == 1 { 1264 return optionalDefault[0] 1265 } 1266 return 0 1267} 1268 1269// MustUint gets the value as a uint. 1270// 1271// Panics if the object is not a uint. 1272func (v *Value) MustUint() uint { 1273 return v.data.(uint) 1274} 1275 1276// UintSlice gets the value as a []uint, returns the optionalDefault 1277// value or nil if the value is not a []uint. 1278func (v *Value) UintSlice(optionalDefault ...[]uint) []uint { 1279 if s, ok := v.data.([]uint); ok { 1280 return s 1281 } 1282 if len(optionalDefault) == 1 { 1283 return optionalDefault[0] 1284 } 1285 return nil 1286} 1287 1288// MustUintSlice gets the value as a []uint. 1289// 1290// Panics if the object is not a []uint. 1291func (v *Value) MustUintSlice() []uint { 1292 return v.data.([]uint) 1293} 1294 1295// IsUint gets whether the object contained is a uint or not. 1296func (v *Value) IsUint() bool { 1297 _, ok := v.data.(uint) 1298 return ok 1299} 1300 1301// IsUintSlice gets whether the object contained is a []uint or not. 1302func (v *Value) IsUintSlice() bool { 1303 _, ok := v.data.([]uint) 1304 return ok 1305} 1306 1307// EachUint calls the specified callback for each object 1308// in the []uint. 1309// 1310// Panics if the object is the wrong type. 1311func (v *Value) EachUint(callback func(int, uint) bool) *Value { 1312 for index, val := range v.MustUintSlice() { 1313 carryon := callback(index, val) 1314 if !carryon { 1315 break 1316 } 1317 } 1318 return v 1319} 1320 1321// WhereUint uses the specified decider function to select items 1322// from the []uint. The object contained in the result will contain 1323// only the selected items. 1324func (v *Value) WhereUint(decider func(int, uint) bool) *Value { 1325 var selected []uint 1326 v.EachUint(func(index int, val uint) bool { 1327 shouldSelect := decider(index, val) 1328 if !shouldSelect { 1329 selected = append(selected, val) 1330 } 1331 return true 1332 }) 1333 return &Value{data: selected} 1334} 1335 1336// GroupUint uses the specified grouper function to group the items 1337// keyed by the return of the grouper. The object contained in the 1338// result will contain a map[string][]uint. 1339func (v *Value) GroupUint(grouper func(int, uint) string) *Value { 1340 groups := make(map[string][]uint) 1341 v.EachUint(func(index int, val uint) bool { 1342 group := grouper(index, val) 1343 if _, ok := groups[group]; !ok { 1344 groups[group] = make([]uint, 0) 1345 } 1346 groups[group] = append(groups[group], val) 1347 return true 1348 }) 1349 return &Value{data: groups} 1350} 1351 1352// ReplaceUint uses the specified function to replace each uints 1353// by iterating each item. The data in the returned result will be a 1354// []uint containing the replaced items. 1355func (v *Value) ReplaceUint(replacer func(int, uint) uint) *Value { 1356 arr := v.MustUintSlice() 1357 replaced := make([]uint, len(arr)) 1358 v.EachUint(func(index int, val uint) bool { 1359 replaced[index] = replacer(index, val) 1360 return true 1361 }) 1362 return &Value{data: replaced} 1363} 1364 1365// CollectUint uses the specified collector function to collect a value 1366// for each of the uints in the slice. The data returned will be a 1367// []interface{}. 1368func (v *Value) CollectUint(collector func(int, uint) interface{}) *Value { 1369 arr := v.MustUintSlice() 1370 collected := make([]interface{}, len(arr)) 1371 v.EachUint(func(index int, val uint) bool { 1372 collected[index] = collector(index, val) 1373 return true 1374 }) 1375 return &Value{data: collected} 1376} 1377 1378/* 1379 Uint8 (uint8 and []uint8) 1380*/ 1381 1382// Uint8 gets the value as a uint8, returns the optionalDefault 1383// value or a system default object if the value is the wrong type. 1384func (v *Value) Uint8(optionalDefault ...uint8) uint8 { 1385 if s, ok := v.data.(uint8); ok { 1386 return s 1387 } 1388 if len(optionalDefault) == 1 { 1389 return optionalDefault[0] 1390 } 1391 return 0 1392} 1393 1394// MustUint8 gets the value as a uint8. 1395// 1396// Panics if the object is not a uint8. 1397func (v *Value) MustUint8() uint8 { 1398 return v.data.(uint8) 1399} 1400 1401// Uint8Slice gets the value as a []uint8, returns the optionalDefault 1402// value or nil if the value is not a []uint8. 1403func (v *Value) Uint8Slice(optionalDefault ...[]uint8) []uint8 { 1404 if s, ok := v.data.([]uint8); ok { 1405 return s 1406 } 1407 if len(optionalDefault) == 1 { 1408 return optionalDefault[0] 1409 } 1410 return nil 1411} 1412 1413// MustUint8Slice gets the value as a []uint8. 1414// 1415// Panics if the object is not a []uint8. 1416func (v *Value) MustUint8Slice() []uint8 { 1417 return v.data.([]uint8) 1418} 1419 1420// IsUint8 gets whether the object contained is a uint8 or not. 1421func (v *Value) IsUint8() bool { 1422 _, ok := v.data.(uint8) 1423 return ok 1424} 1425 1426// IsUint8Slice gets whether the object contained is a []uint8 or not. 1427func (v *Value) IsUint8Slice() bool { 1428 _, ok := v.data.([]uint8) 1429 return ok 1430} 1431 1432// EachUint8 calls the specified callback for each object 1433// in the []uint8. 1434// 1435// Panics if the object is the wrong type. 1436func (v *Value) EachUint8(callback func(int, uint8) bool) *Value { 1437 for index, val := range v.MustUint8Slice() { 1438 carryon := callback(index, val) 1439 if !carryon { 1440 break 1441 } 1442 } 1443 return v 1444} 1445 1446// WhereUint8 uses the specified decider function to select items 1447// from the []uint8. The object contained in the result will contain 1448// only the selected items. 1449func (v *Value) WhereUint8(decider func(int, uint8) bool) *Value { 1450 var selected []uint8 1451 v.EachUint8(func(index int, val uint8) bool { 1452 shouldSelect := decider(index, val) 1453 if !shouldSelect { 1454 selected = append(selected, val) 1455 } 1456 return true 1457 }) 1458 return &Value{data: selected} 1459} 1460 1461// GroupUint8 uses the specified grouper function to group the items 1462// keyed by the return of the grouper. The object contained in the 1463// result will contain a map[string][]uint8. 1464func (v *Value) GroupUint8(grouper func(int, uint8) string) *Value { 1465 groups := make(map[string][]uint8) 1466 v.EachUint8(func(index int, val uint8) bool { 1467 group := grouper(index, val) 1468 if _, ok := groups[group]; !ok { 1469 groups[group] = make([]uint8, 0) 1470 } 1471 groups[group] = append(groups[group], val) 1472 return true 1473 }) 1474 return &Value{data: groups} 1475} 1476 1477// ReplaceUint8 uses the specified function to replace each uint8s 1478// by iterating each item. The data in the returned result will be a 1479// []uint8 containing the replaced items. 1480func (v *Value) ReplaceUint8(replacer func(int, uint8) uint8) *Value { 1481 arr := v.MustUint8Slice() 1482 replaced := make([]uint8, len(arr)) 1483 v.EachUint8(func(index int, val uint8) bool { 1484 replaced[index] = replacer(index, val) 1485 return true 1486 }) 1487 return &Value{data: replaced} 1488} 1489 1490// CollectUint8 uses the specified collector function to collect a value 1491// for each of the uint8s in the slice. The data returned will be a 1492// []interface{}. 1493func (v *Value) CollectUint8(collector func(int, uint8) interface{}) *Value { 1494 arr := v.MustUint8Slice() 1495 collected := make([]interface{}, len(arr)) 1496 v.EachUint8(func(index int, val uint8) bool { 1497 collected[index] = collector(index, val) 1498 return true 1499 }) 1500 return &Value{data: collected} 1501} 1502 1503/* 1504 Uint16 (uint16 and []uint16) 1505*/ 1506 1507// Uint16 gets the value as a uint16, returns the optionalDefault 1508// value or a system default object if the value is the wrong type. 1509func (v *Value) Uint16(optionalDefault ...uint16) uint16 { 1510 if s, ok := v.data.(uint16); ok { 1511 return s 1512 } 1513 if len(optionalDefault) == 1 { 1514 return optionalDefault[0] 1515 } 1516 return 0 1517} 1518 1519// MustUint16 gets the value as a uint16. 1520// 1521// Panics if the object is not a uint16. 1522func (v *Value) MustUint16() uint16 { 1523 return v.data.(uint16) 1524} 1525 1526// Uint16Slice gets the value as a []uint16, returns the optionalDefault 1527// value or nil if the value is not a []uint16. 1528func (v *Value) Uint16Slice(optionalDefault ...[]uint16) []uint16 { 1529 if s, ok := v.data.([]uint16); ok { 1530 return s 1531 } 1532 if len(optionalDefault) == 1 { 1533 return optionalDefault[0] 1534 } 1535 return nil 1536} 1537 1538// MustUint16Slice gets the value as a []uint16. 1539// 1540// Panics if the object is not a []uint16. 1541func (v *Value) MustUint16Slice() []uint16 { 1542 return v.data.([]uint16) 1543} 1544 1545// IsUint16 gets whether the object contained is a uint16 or not. 1546func (v *Value) IsUint16() bool { 1547 _, ok := v.data.(uint16) 1548 return ok 1549} 1550 1551// IsUint16Slice gets whether the object contained is a []uint16 or not. 1552func (v *Value) IsUint16Slice() bool { 1553 _, ok := v.data.([]uint16) 1554 return ok 1555} 1556 1557// EachUint16 calls the specified callback for each object 1558// in the []uint16. 1559// 1560// Panics if the object is the wrong type. 1561func (v *Value) EachUint16(callback func(int, uint16) bool) *Value { 1562 for index, val := range v.MustUint16Slice() { 1563 carryon := callback(index, val) 1564 if !carryon { 1565 break 1566 } 1567 } 1568 return v 1569} 1570 1571// WhereUint16 uses the specified decider function to select items 1572// from the []uint16. The object contained in the result will contain 1573// only the selected items. 1574func (v *Value) WhereUint16(decider func(int, uint16) bool) *Value { 1575 var selected []uint16 1576 v.EachUint16(func(index int, val uint16) bool { 1577 shouldSelect := decider(index, val) 1578 if !shouldSelect { 1579 selected = append(selected, val) 1580 } 1581 return true 1582 }) 1583 return &Value{data: selected} 1584} 1585 1586// GroupUint16 uses the specified grouper function to group the items 1587// keyed by the return of the grouper. The object contained in the 1588// result will contain a map[string][]uint16. 1589func (v *Value) GroupUint16(grouper func(int, uint16) string) *Value { 1590 groups := make(map[string][]uint16) 1591 v.EachUint16(func(index int, val uint16) bool { 1592 group := grouper(index, val) 1593 if _, ok := groups[group]; !ok { 1594 groups[group] = make([]uint16, 0) 1595 } 1596 groups[group] = append(groups[group], val) 1597 return true 1598 }) 1599 return &Value{data: groups} 1600} 1601 1602// ReplaceUint16 uses the specified function to replace each uint16s 1603// by iterating each item. The data in the returned result will be a 1604// []uint16 containing the replaced items. 1605func (v *Value) ReplaceUint16(replacer func(int, uint16) uint16) *Value { 1606 arr := v.MustUint16Slice() 1607 replaced := make([]uint16, len(arr)) 1608 v.EachUint16(func(index int, val uint16) bool { 1609 replaced[index] = replacer(index, val) 1610 return true 1611 }) 1612 return &Value{data: replaced} 1613} 1614 1615// CollectUint16 uses the specified collector function to collect a value 1616// for each of the uint16s in the slice. The data returned will be a 1617// []interface{}. 1618func (v *Value) CollectUint16(collector func(int, uint16) interface{}) *Value { 1619 arr := v.MustUint16Slice() 1620 collected := make([]interface{}, len(arr)) 1621 v.EachUint16(func(index int, val uint16) bool { 1622 collected[index] = collector(index, val) 1623 return true 1624 }) 1625 return &Value{data: collected} 1626} 1627 1628/* 1629 Uint32 (uint32 and []uint32) 1630*/ 1631 1632// Uint32 gets the value as a uint32, returns the optionalDefault 1633// value or a system default object if the value is the wrong type. 1634func (v *Value) Uint32(optionalDefault ...uint32) uint32 { 1635 if s, ok := v.data.(uint32); ok { 1636 return s 1637 } 1638 if len(optionalDefault) == 1 { 1639 return optionalDefault[0] 1640 } 1641 return 0 1642} 1643 1644// MustUint32 gets the value as a uint32. 1645// 1646// Panics if the object is not a uint32. 1647func (v *Value) MustUint32() uint32 { 1648 return v.data.(uint32) 1649} 1650 1651// Uint32Slice gets the value as a []uint32, returns the optionalDefault 1652// value or nil if the value is not a []uint32. 1653func (v *Value) Uint32Slice(optionalDefault ...[]uint32) []uint32 { 1654 if s, ok := v.data.([]uint32); ok { 1655 return s 1656 } 1657 if len(optionalDefault) == 1 { 1658 return optionalDefault[0] 1659 } 1660 return nil 1661} 1662 1663// MustUint32Slice gets the value as a []uint32. 1664// 1665// Panics if the object is not a []uint32. 1666func (v *Value) MustUint32Slice() []uint32 { 1667 return v.data.([]uint32) 1668} 1669 1670// IsUint32 gets whether the object contained is a uint32 or not. 1671func (v *Value) IsUint32() bool { 1672 _, ok := v.data.(uint32) 1673 return ok 1674} 1675 1676// IsUint32Slice gets whether the object contained is a []uint32 or not. 1677func (v *Value) IsUint32Slice() bool { 1678 _, ok := v.data.([]uint32) 1679 return ok 1680} 1681 1682// EachUint32 calls the specified callback for each object 1683// in the []uint32. 1684// 1685// Panics if the object is the wrong type. 1686func (v *Value) EachUint32(callback func(int, uint32) bool) *Value { 1687 for index, val := range v.MustUint32Slice() { 1688 carryon := callback(index, val) 1689 if !carryon { 1690 break 1691 } 1692 } 1693 return v 1694} 1695 1696// WhereUint32 uses the specified decider function to select items 1697// from the []uint32. The object contained in the result will contain 1698// only the selected items. 1699func (v *Value) WhereUint32(decider func(int, uint32) bool) *Value { 1700 var selected []uint32 1701 v.EachUint32(func(index int, val uint32) bool { 1702 shouldSelect := decider(index, val) 1703 if !shouldSelect { 1704 selected = append(selected, val) 1705 } 1706 return true 1707 }) 1708 return &Value{data: selected} 1709} 1710 1711// GroupUint32 uses the specified grouper function to group the items 1712// keyed by the return of the grouper. The object contained in the 1713// result will contain a map[string][]uint32. 1714func (v *Value) GroupUint32(grouper func(int, uint32) string) *Value { 1715 groups := make(map[string][]uint32) 1716 v.EachUint32(func(index int, val uint32) bool { 1717 group := grouper(index, val) 1718 if _, ok := groups[group]; !ok { 1719 groups[group] = make([]uint32, 0) 1720 } 1721 groups[group] = append(groups[group], val) 1722 return true 1723 }) 1724 return &Value{data: groups} 1725} 1726 1727// ReplaceUint32 uses the specified function to replace each uint32s 1728// by iterating each item. The data in the returned result will be a 1729// []uint32 containing the replaced items. 1730func (v *Value) ReplaceUint32(replacer func(int, uint32) uint32) *Value { 1731 arr := v.MustUint32Slice() 1732 replaced := make([]uint32, len(arr)) 1733 v.EachUint32(func(index int, val uint32) bool { 1734 replaced[index] = replacer(index, val) 1735 return true 1736 }) 1737 return &Value{data: replaced} 1738} 1739 1740// CollectUint32 uses the specified collector function to collect a value 1741// for each of the uint32s in the slice. The data returned will be a 1742// []interface{}. 1743func (v *Value) CollectUint32(collector func(int, uint32) interface{}) *Value { 1744 arr := v.MustUint32Slice() 1745 collected := make([]interface{}, len(arr)) 1746 v.EachUint32(func(index int, val uint32) bool { 1747 collected[index] = collector(index, val) 1748 return true 1749 }) 1750 return &Value{data: collected} 1751} 1752 1753/* 1754 Uint64 (uint64 and []uint64) 1755*/ 1756 1757// Uint64 gets the value as a uint64, returns the optionalDefault 1758// value or a system default object if the value is the wrong type. 1759func (v *Value) Uint64(optionalDefault ...uint64) uint64 { 1760 if s, ok := v.data.(uint64); ok { 1761 return s 1762 } 1763 if len(optionalDefault) == 1 { 1764 return optionalDefault[0] 1765 } 1766 return 0 1767} 1768 1769// MustUint64 gets the value as a uint64. 1770// 1771// Panics if the object is not a uint64. 1772func (v *Value) MustUint64() uint64 { 1773 return v.data.(uint64) 1774} 1775 1776// Uint64Slice gets the value as a []uint64, returns the optionalDefault 1777// value or nil if the value is not a []uint64. 1778func (v *Value) Uint64Slice(optionalDefault ...[]uint64) []uint64 { 1779 if s, ok := v.data.([]uint64); ok { 1780 return s 1781 } 1782 if len(optionalDefault) == 1 { 1783 return optionalDefault[0] 1784 } 1785 return nil 1786} 1787 1788// MustUint64Slice gets the value as a []uint64. 1789// 1790// Panics if the object is not a []uint64. 1791func (v *Value) MustUint64Slice() []uint64 { 1792 return v.data.([]uint64) 1793} 1794 1795// IsUint64 gets whether the object contained is a uint64 or not. 1796func (v *Value) IsUint64() bool { 1797 _, ok := v.data.(uint64) 1798 return ok 1799} 1800 1801// IsUint64Slice gets whether the object contained is a []uint64 or not. 1802func (v *Value) IsUint64Slice() bool { 1803 _, ok := v.data.([]uint64) 1804 return ok 1805} 1806 1807// EachUint64 calls the specified callback for each object 1808// in the []uint64. 1809// 1810// Panics if the object is the wrong type. 1811func (v *Value) EachUint64(callback func(int, uint64) bool) *Value { 1812 for index, val := range v.MustUint64Slice() { 1813 carryon := callback(index, val) 1814 if !carryon { 1815 break 1816 } 1817 } 1818 return v 1819} 1820 1821// WhereUint64 uses the specified decider function to select items 1822// from the []uint64. The object contained in the result will contain 1823// only the selected items. 1824func (v *Value) WhereUint64(decider func(int, uint64) bool) *Value { 1825 var selected []uint64 1826 v.EachUint64(func(index int, val uint64) bool { 1827 shouldSelect := decider(index, val) 1828 if !shouldSelect { 1829 selected = append(selected, val) 1830 } 1831 return true 1832 }) 1833 return &Value{data: selected} 1834} 1835 1836// GroupUint64 uses the specified grouper function to group the items 1837// keyed by the return of the grouper. The object contained in the 1838// result will contain a map[string][]uint64. 1839func (v *Value) GroupUint64(grouper func(int, uint64) string) *Value { 1840 groups := make(map[string][]uint64) 1841 v.EachUint64(func(index int, val uint64) bool { 1842 group := grouper(index, val) 1843 if _, ok := groups[group]; !ok { 1844 groups[group] = make([]uint64, 0) 1845 } 1846 groups[group] = append(groups[group], val) 1847 return true 1848 }) 1849 return &Value{data: groups} 1850} 1851 1852// ReplaceUint64 uses the specified function to replace each uint64s 1853// by iterating each item. The data in the returned result will be a 1854// []uint64 containing the replaced items. 1855func (v *Value) ReplaceUint64(replacer func(int, uint64) uint64) *Value { 1856 arr := v.MustUint64Slice() 1857 replaced := make([]uint64, len(arr)) 1858 v.EachUint64(func(index int, val uint64) bool { 1859 replaced[index] = replacer(index, val) 1860 return true 1861 }) 1862 return &Value{data: replaced} 1863} 1864 1865// CollectUint64 uses the specified collector function to collect a value 1866// for each of the uint64s in the slice. The data returned will be a 1867// []interface{}. 1868func (v *Value) CollectUint64(collector func(int, uint64) interface{}) *Value { 1869 arr := v.MustUint64Slice() 1870 collected := make([]interface{}, len(arr)) 1871 v.EachUint64(func(index int, val uint64) bool { 1872 collected[index] = collector(index, val) 1873 return true 1874 }) 1875 return &Value{data: collected} 1876} 1877 1878/* 1879 Uintptr (uintptr and []uintptr) 1880*/ 1881 1882// Uintptr gets the value as a uintptr, returns the optionalDefault 1883// value or a system default object if the value is the wrong type. 1884func (v *Value) Uintptr(optionalDefault ...uintptr) uintptr { 1885 if s, ok := v.data.(uintptr); ok { 1886 return s 1887 } 1888 if len(optionalDefault) == 1 { 1889 return optionalDefault[0] 1890 } 1891 return 0 1892} 1893 1894// MustUintptr gets the value as a uintptr. 1895// 1896// Panics if the object is not a uintptr. 1897func (v *Value) MustUintptr() uintptr { 1898 return v.data.(uintptr) 1899} 1900 1901// UintptrSlice gets the value as a []uintptr, returns the optionalDefault 1902// value or nil if the value is not a []uintptr. 1903func (v *Value) UintptrSlice(optionalDefault ...[]uintptr) []uintptr { 1904 if s, ok := v.data.([]uintptr); ok { 1905 return s 1906 } 1907 if len(optionalDefault) == 1 { 1908 return optionalDefault[0] 1909 } 1910 return nil 1911} 1912 1913// MustUintptrSlice gets the value as a []uintptr. 1914// 1915// Panics if the object is not a []uintptr. 1916func (v *Value) MustUintptrSlice() []uintptr { 1917 return v.data.([]uintptr) 1918} 1919 1920// IsUintptr gets whether the object contained is a uintptr or not. 1921func (v *Value) IsUintptr() bool { 1922 _, ok := v.data.(uintptr) 1923 return ok 1924} 1925 1926// IsUintptrSlice gets whether the object contained is a []uintptr or not. 1927func (v *Value) IsUintptrSlice() bool { 1928 _, ok := v.data.([]uintptr) 1929 return ok 1930} 1931 1932// EachUintptr calls the specified callback for each object 1933// in the []uintptr. 1934// 1935// Panics if the object is the wrong type. 1936func (v *Value) EachUintptr(callback func(int, uintptr) bool) *Value { 1937 for index, val := range v.MustUintptrSlice() { 1938 carryon := callback(index, val) 1939 if !carryon { 1940 break 1941 } 1942 } 1943 return v 1944} 1945 1946// WhereUintptr uses the specified decider function to select items 1947// from the []uintptr. The object contained in the result will contain 1948// only the selected items. 1949func (v *Value) WhereUintptr(decider func(int, uintptr) bool) *Value { 1950 var selected []uintptr 1951 v.EachUintptr(func(index int, val uintptr) bool { 1952 shouldSelect := decider(index, val) 1953 if !shouldSelect { 1954 selected = append(selected, val) 1955 } 1956 return true 1957 }) 1958 return &Value{data: selected} 1959} 1960 1961// GroupUintptr uses the specified grouper function to group the items 1962// keyed by the return of the grouper. The object contained in the 1963// result will contain a map[string][]uintptr. 1964func (v *Value) GroupUintptr(grouper func(int, uintptr) string) *Value { 1965 groups := make(map[string][]uintptr) 1966 v.EachUintptr(func(index int, val uintptr) bool { 1967 group := grouper(index, val) 1968 if _, ok := groups[group]; !ok { 1969 groups[group] = make([]uintptr, 0) 1970 } 1971 groups[group] = append(groups[group], val) 1972 return true 1973 }) 1974 return &Value{data: groups} 1975} 1976 1977// ReplaceUintptr uses the specified function to replace each uintptrs 1978// by iterating each item. The data in the returned result will be a 1979// []uintptr containing the replaced items. 1980func (v *Value) ReplaceUintptr(replacer func(int, uintptr) uintptr) *Value { 1981 arr := v.MustUintptrSlice() 1982 replaced := make([]uintptr, len(arr)) 1983 v.EachUintptr(func(index int, val uintptr) bool { 1984 replaced[index] = replacer(index, val) 1985 return true 1986 }) 1987 return &Value{data: replaced} 1988} 1989 1990// CollectUintptr uses the specified collector function to collect a value 1991// for each of the uintptrs in the slice. The data returned will be a 1992// []interface{}. 1993func (v *Value) CollectUintptr(collector func(int, uintptr) interface{}) *Value { 1994 arr := v.MustUintptrSlice() 1995 collected := make([]interface{}, len(arr)) 1996 v.EachUintptr(func(index int, val uintptr) bool { 1997 collected[index] = collector(index, val) 1998 return true 1999 }) 2000 return &Value{data: collected} 2001} 2002 2003/* 2004 Float32 (float32 and []float32) 2005*/ 2006 2007// Float32 gets the value as a float32, returns the optionalDefault 2008// value or a system default object if the value is the wrong type. 2009func (v *Value) Float32(optionalDefault ...float32) float32 { 2010 if s, ok := v.data.(float32); ok { 2011 return s 2012 } 2013 if len(optionalDefault) == 1 { 2014 return optionalDefault[0] 2015 } 2016 return 0 2017} 2018 2019// MustFloat32 gets the value as a float32. 2020// 2021// Panics if the object is not a float32. 2022func (v *Value) MustFloat32() float32 { 2023 return v.data.(float32) 2024} 2025 2026// Float32Slice gets the value as a []float32, returns the optionalDefault 2027// value or nil if the value is not a []float32. 2028func (v *Value) Float32Slice(optionalDefault ...[]float32) []float32 { 2029 if s, ok := v.data.([]float32); ok { 2030 return s 2031 } 2032 if len(optionalDefault) == 1 { 2033 return optionalDefault[0] 2034 } 2035 return nil 2036} 2037 2038// MustFloat32Slice gets the value as a []float32. 2039// 2040// Panics if the object is not a []float32. 2041func (v *Value) MustFloat32Slice() []float32 { 2042 return v.data.([]float32) 2043} 2044 2045// IsFloat32 gets whether the object contained is a float32 or not. 2046func (v *Value) IsFloat32() bool { 2047 _, ok := v.data.(float32) 2048 return ok 2049} 2050 2051// IsFloat32Slice gets whether the object contained is a []float32 or not. 2052func (v *Value) IsFloat32Slice() bool { 2053 _, ok := v.data.([]float32) 2054 return ok 2055} 2056 2057// EachFloat32 calls the specified callback for each object 2058// in the []float32. 2059// 2060// Panics if the object is the wrong type. 2061func (v *Value) EachFloat32(callback func(int, float32) bool) *Value { 2062 for index, val := range v.MustFloat32Slice() { 2063 carryon := callback(index, val) 2064 if !carryon { 2065 break 2066 } 2067 } 2068 return v 2069} 2070 2071// WhereFloat32 uses the specified decider function to select items 2072// from the []float32. The object contained in the result will contain 2073// only the selected items. 2074func (v *Value) WhereFloat32(decider func(int, float32) bool) *Value { 2075 var selected []float32 2076 v.EachFloat32(func(index int, val float32) bool { 2077 shouldSelect := decider(index, val) 2078 if !shouldSelect { 2079 selected = append(selected, val) 2080 } 2081 return true 2082 }) 2083 return &Value{data: selected} 2084} 2085 2086// GroupFloat32 uses the specified grouper function to group the items 2087// keyed by the return of the grouper. The object contained in the 2088// result will contain a map[string][]float32. 2089func (v *Value) GroupFloat32(grouper func(int, float32) string) *Value { 2090 groups := make(map[string][]float32) 2091 v.EachFloat32(func(index int, val float32) bool { 2092 group := grouper(index, val) 2093 if _, ok := groups[group]; !ok { 2094 groups[group] = make([]float32, 0) 2095 } 2096 groups[group] = append(groups[group], val) 2097 return true 2098 }) 2099 return &Value{data: groups} 2100} 2101 2102// ReplaceFloat32 uses the specified function to replace each float32s 2103// by iterating each item. The data in the returned result will be a 2104// []float32 containing the replaced items. 2105func (v *Value) ReplaceFloat32(replacer func(int, float32) float32) *Value { 2106 arr := v.MustFloat32Slice() 2107 replaced := make([]float32, len(arr)) 2108 v.EachFloat32(func(index int, val float32) bool { 2109 replaced[index] = replacer(index, val) 2110 return true 2111 }) 2112 return &Value{data: replaced} 2113} 2114 2115// CollectFloat32 uses the specified collector function to collect a value 2116// for each of the float32s in the slice. The data returned will be a 2117// []interface{}. 2118func (v *Value) CollectFloat32(collector func(int, float32) interface{}) *Value { 2119 arr := v.MustFloat32Slice() 2120 collected := make([]interface{}, len(arr)) 2121 v.EachFloat32(func(index int, val float32) bool { 2122 collected[index] = collector(index, val) 2123 return true 2124 }) 2125 return &Value{data: collected} 2126} 2127 2128/* 2129 Float64 (float64 and []float64) 2130*/ 2131 2132// Float64 gets the value as a float64, returns the optionalDefault 2133// value or a system default object if the value is the wrong type. 2134func (v *Value) Float64(optionalDefault ...float64) float64 { 2135 if s, ok := v.data.(float64); ok { 2136 return s 2137 } 2138 if len(optionalDefault) == 1 { 2139 return optionalDefault[0] 2140 } 2141 return 0 2142} 2143 2144// MustFloat64 gets the value as a float64. 2145// 2146// Panics if the object is not a float64. 2147func (v *Value) MustFloat64() float64 { 2148 return v.data.(float64) 2149} 2150 2151// Float64Slice gets the value as a []float64, returns the optionalDefault 2152// value or nil if the value is not a []float64. 2153func (v *Value) Float64Slice(optionalDefault ...[]float64) []float64 { 2154 if s, ok := v.data.([]float64); ok { 2155 return s 2156 } 2157 if len(optionalDefault) == 1 { 2158 return optionalDefault[0] 2159 } 2160 return nil 2161} 2162 2163// MustFloat64Slice gets the value as a []float64. 2164// 2165// Panics if the object is not a []float64. 2166func (v *Value) MustFloat64Slice() []float64 { 2167 return v.data.([]float64) 2168} 2169 2170// IsFloat64 gets whether the object contained is a float64 or not. 2171func (v *Value) IsFloat64() bool { 2172 _, ok := v.data.(float64) 2173 return ok 2174} 2175 2176// IsFloat64Slice gets whether the object contained is a []float64 or not. 2177func (v *Value) IsFloat64Slice() bool { 2178 _, ok := v.data.([]float64) 2179 return ok 2180} 2181 2182// EachFloat64 calls the specified callback for each object 2183// in the []float64. 2184// 2185// Panics if the object is the wrong type. 2186func (v *Value) EachFloat64(callback func(int, float64) bool) *Value { 2187 for index, val := range v.MustFloat64Slice() { 2188 carryon := callback(index, val) 2189 if !carryon { 2190 break 2191 } 2192 } 2193 return v 2194} 2195 2196// WhereFloat64 uses the specified decider function to select items 2197// from the []float64. The object contained in the result will contain 2198// only the selected items. 2199func (v *Value) WhereFloat64(decider func(int, float64) bool) *Value { 2200 var selected []float64 2201 v.EachFloat64(func(index int, val float64) bool { 2202 shouldSelect := decider(index, val) 2203 if !shouldSelect { 2204 selected = append(selected, val) 2205 } 2206 return true 2207 }) 2208 return &Value{data: selected} 2209} 2210 2211// GroupFloat64 uses the specified grouper function to group the items 2212// keyed by the return of the grouper. The object contained in the 2213// result will contain a map[string][]float64. 2214func (v *Value) GroupFloat64(grouper func(int, float64) string) *Value { 2215 groups := make(map[string][]float64) 2216 v.EachFloat64(func(index int, val float64) bool { 2217 group := grouper(index, val) 2218 if _, ok := groups[group]; !ok { 2219 groups[group] = make([]float64, 0) 2220 } 2221 groups[group] = append(groups[group], val) 2222 return true 2223 }) 2224 return &Value{data: groups} 2225} 2226 2227// ReplaceFloat64 uses the specified function to replace each float64s 2228// by iterating each item. The data in the returned result will be a 2229// []float64 containing the replaced items. 2230func (v *Value) ReplaceFloat64(replacer func(int, float64) float64) *Value { 2231 arr := v.MustFloat64Slice() 2232 replaced := make([]float64, len(arr)) 2233 v.EachFloat64(func(index int, val float64) bool { 2234 replaced[index] = replacer(index, val) 2235 return true 2236 }) 2237 return &Value{data: replaced} 2238} 2239 2240// CollectFloat64 uses the specified collector function to collect a value 2241// for each of the float64s in the slice. The data returned will be a 2242// []interface{}. 2243func (v *Value) CollectFloat64(collector func(int, float64) interface{}) *Value { 2244 arr := v.MustFloat64Slice() 2245 collected := make([]interface{}, len(arr)) 2246 v.EachFloat64(func(index int, val float64) bool { 2247 collected[index] = collector(index, val) 2248 return true 2249 }) 2250 return &Value{data: collected} 2251} 2252 2253/* 2254 Complex64 (complex64 and []complex64) 2255*/ 2256 2257// Complex64 gets the value as a complex64, returns the optionalDefault 2258// value or a system default object if the value is the wrong type. 2259func (v *Value) Complex64(optionalDefault ...complex64) complex64 { 2260 if s, ok := v.data.(complex64); ok { 2261 return s 2262 } 2263 if len(optionalDefault) == 1 { 2264 return optionalDefault[0] 2265 } 2266 return 0 2267} 2268 2269// MustComplex64 gets the value as a complex64. 2270// 2271// Panics if the object is not a complex64. 2272func (v *Value) MustComplex64() complex64 { 2273 return v.data.(complex64) 2274} 2275 2276// Complex64Slice gets the value as a []complex64, returns the optionalDefault 2277// value or nil if the value is not a []complex64. 2278func (v *Value) Complex64Slice(optionalDefault ...[]complex64) []complex64 { 2279 if s, ok := v.data.([]complex64); ok { 2280 return s 2281 } 2282 if len(optionalDefault) == 1 { 2283 return optionalDefault[0] 2284 } 2285 return nil 2286} 2287 2288// MustComplex64Slice gets the value as a []complex64. 2289// 2290// Panics if the object is not a []complex64. 2291func (v *Value) MustComplex64Slice() []complex64 { 2292 return v.data.([]complex64) 2293} 2294 2295// IsComplex64 gets whether the object contained is a complex64 or not. 2296func (v *Value) IsComplex64() bool { 2297 _, ok := v.data.(complex64) 2298 return ok 2299} 2300 2301// IsComplex64Slice gets whether the object contained is a []complex64 or not. 2302func (v *Value) IsComplex64Slice() bool { 2303 _, ok := v.data.([]complex64) 2304 return ok 2305} 2306 2307// EachComplex64 calls the specified callback for each object 2308// in the []complex64. 2309// 2310// Panics if the object is the wrong type. 2311func (v *Value) EachComplex64(callback func(int, complex64) bool) *Value { 2312 for index, val := range v.MustComplex64Slice() { 2313 carryon := callback(index, val) 2314 if !carryon { 2315 break 2316 } 2317 } 2318 return v 2319} 2320 2321// WhereComplex64 uses the specified decider function to select items 2322// from the []complex64. The object contained in the result will contain 2323// only the selected items. 2324func (v *Value) WhereComplex64(decider func(int, complex64) bool) *Value { 2325 var selected []complex64 2326 v.EachComplex64(func(index int, val complex64) bool { 2327 shouldSelect := decider(index, val) 2328 if !shouldSelect { 2329 selected = append(selected, val) 2330 } 2331 return true 2332 }) 2333 return &Value{data: selected} 2334} 2335 2336// GroupComplex64 uses the specified grouper function to group the items 2337// keyed by the return of the grouper. The object contained in the 2338// result will contain a map[string][]complex64. 2339func (v *Value) GroupComplex64(grouper func(int, complex64) string) *Value { 2340 groups := make(map[string][]complex64) 2341 v.EachComplex64(func(index int, val complex64) bool { 2342 group := grouper(index, val) 2343 if _, ok := groups[group]; !ok { 2344 groups[group] = make([]complex64, 0) 2345 } 2346 groups[group] = append(groups[group], val) 2347 return true 2348 }) 2349 return &Value{data: groups} 2350} 2351 2352// ReplaceComplex64 uses the specified function to replace each complex64s 2353// by iterating each item. The data in the returned result will be a 2354// []complex64 containing the replaced items. 2355func (v *Value) ReplaceComplex64(replacer func(int, complex64) complex64) *Value { 2356 arr := v.MustComplex64Slice() 2357 replaced := make([]complex64, len(arr)) 2358 v.EachComplex64(func(index int, val complex64) bool { 2359 replaced[index] = replacer(index, val) 2360 return true 2361 }) 2362 return &Value{data: replaced} 2363} 2364 2365// CollectComplex64 uses the specified collector function to collect a value 2366// for each of the complex64s in the slice. The data returned will be a 2367// []interface{}. 2368func (v *Value) CollectComplex64(collector func(int, complex64) interface{}) *Value { 2369 arr := v.MustComplex64Slice() 2370 collected := make([]interface{}, len(arr)) 2371 v.EachComplex64(func(index int, val complex64) bool { 2372 collected[index] = collector(index, val) 2373 return true 2374 }) 2375 return &Value{data: collected} 2376} 2377 2378/* 2379 Complex128 (complex128 and []complex128) 2380*/ 2381 2382// Complex128 gets the value as a complex128, returns the optionalDefault 2383// value or a system default object if the value is the wrong type. 2384func (v *Value) Complex128(optionalDefault ...complex128) complex128 { 2385 if s, ok := v.data.(complex128); ok { 2386 return s 2387 } 2388 if len(optionalDefault) == 1 { 2389 return optionalDefault[0] 2390 } 2391 return 0 2392} 2393 2394// MustComplex128 gets the value as a complex128. 2395// 2396// Panics if the object is not a complex128. 2397func (v *Value) MustComplex128() complex128 { 2398 return v.data.(complex128) 2399} 2400 2401// Complex128Slice gets the value as a []complex128, returns the optionalDefault 2402// value or nil if the value is not a []complex128. 2403func (v *Value) Complex128Slice(optionalDefault ...[]complex128) []complex128 { 2404 if s, ok := v.data.([]complex128); ok { 2405 return s 2406 } 2407 if len(optionalDefault) == 1 { 2408 return optionalDefault[0] 2409 } 2410 return nil 2411} 2412 2413// MustComplex128Slice gets the value as a []complex128. 2414// 2415// Panics if the object is not a []complex128. 2416func (v *Value) MustComplex128Slice() []complex128 { 2417 return v.data.([]complex128) 2418} 2419 2420// IsComplex128 gets whether the object contained is a complex128 or not. 2421func (v *Value) IsComplex128() bool { 2422 _, ok := v.data.(complex128) 2423 return ok 2424} 2425 2426// IsComplex128Slice gets whether the object contained is a []complex128 or not. 2427func (v *Value) IsComplex128Slice() bool { 2428 _, ok := v.data.([]complex128) 2429 return ok 2430} 2431 2432// EachComplex128 calls the specified callback for each object 2433// in the []complex128. 2434// 2435// Panics if the object is the wrong type. 2436func (v *Value) EachComplex128(callback func(int, complex128) bool) *Value { 2437 for index, val := range v.MustComplex128Slice() { 2438 carryon := callback(index, val) 2439 if !carryon { 2440 break 2441 } 2442 } 2443 return v 2444} 2445 2446// WhereComplex128 uses the specified decider function to select items 2447// from the []complex128. The object contained in the result will contain 2448// only the selected items. 2449func (v *Value) WhereComplex128(decider func(int, complex128) bool) *Value { 2450 var selected []complex128 2451 v.EachComplex128(func(index int, val complex128) bool { 2452 shouldSelect := decider(index, val) 2453 if !shouldSelect { 2454 selected = append(selected, val) 2455 } 2456 return true 2457 }) 2458 return &Value{data: selected} 2459} 2460 2461// GroupComplex128 uses the specified grouper function to group the items 2462// keyed by the return of the grouper. The object contained in the 2463// result will contain a map[string][]complex128. 2464func (v *Value) GroupComplex128(grouper func(int, complex128) string) *Value { 2465 groups := make(map[string][]complex128) 2466 v.EachComplex128(func(index int, val complex128) bool { 2467 group := grouper(index, val) 2468 if _, ok := groups[group]; !ok { 2469 groups[group] = make([]complex128, 0) 2470 } 2471 groups[group] = append(groups[group], val) 2472 return true 2473 }) 2474 return &Value{data: groups} 2475} 2476 2477// ReplaceComplex128 uses the specified function to replace each complex128s 2478// by iterating each item. The data in the returned result will be a 2479// []complex128 containing the replaced items. 2480func (v *Value) ReplaceComplex128(replacer func(int, complex128) complex128) *Value { 2481 arr := v.MustComplex128Slice() 2482 replaced := make([]complex128, len(arr)) 2483 v.EachComplex128(func(index int, val complex128) bool { 2484 replaced[index] = replacer(index, val) 2485 return true 2486 }) 2487 return &Value{data: replaced} 2488} 2489 2490// CollectComplex128 uses the specified collector function to collect a value 2491// for each of the complex128s in the slice. The data returned will be a 2492// []interface{}. 2493func (v *Value) CollectComplex128(collector func(int, complex128) interface{}) *Value { 2494 arr := v.MustComplex128Slice() 2495 collected := make([]interface{}, len(arr)) 2496 v.EachComplex128(func(index int, val complex128) bool { 2497 collected[index] = collector(index, val) 2498 return true 2499 }) 2500 return &Value{data: collected} 2501} 2502