Documentation ¶
Overview ¶
Package n provides a set of types with convenience methods for Go akin to rapid development languages.
n was created to reduce the friction I had adopting Go as my primary language of choice. It does this by reducing the coding verbosity Go normally requires. n types wrap various Go types to provide generic convenience methods reminiscent of C#'s Queryable interface, removing the need to implement the 'Contains' function, on basic list primitives for the millionth time. The intent is at a minimum to have support for YAML primitive scalars (Null, String, Integer, Boolean, Float, Timestamp), lists of the scalar types and maps of the scalar types with reflection based fallbacks for un-optimized types. I'll be using the terms 'n types' or 'queryable' interchangeably in the documentation and examples.
Conventions used across n types and pkgs ¶
• In order to deal with Golang's decision to not support function overloading or special characters in their function names n makes use of a variety of prefix/suffix capital letters to indicate different function variations. The function/method that contains no suffix is referred to as the base function/method.
• Function names suffixed with 'A' indicates the function is a variation to the function without the 'A' but either accepts a string as input or returns a string.
• Function names suffixed with 'E' indicates the function is a variation to the function without the 'E' but returns an Error while the base function does not.
• Function names suffixed with 'M' indicates the function is a variation to the function without the 'M' but modifies the n type directly rather than a copy.
• Function names suffixed with 'R' indicates the function is a variation to the function without the 'R' but reverses the order of operations.
• Function names suffixed with 'S' indicates the function is a variation to the function without the 'S' but either accepts a ISlice as input or returns a ISlice.
• Function names suffixed with 'V' indicates the function is a variation to the function • Function names suffixed with 'V' indicates the function is a variation to the function without the 'V' but accepts variadic input.
• Function names suffixed with 'W' indicates the function is a variation to the function without the 'W' but accepts a lambda expression as input.
• Documentation should be thorough and relied upon for guidance as, for a love of brevity, some functions are named with a single capital letter only. 'G' is being used to export the underlying Go type. 'O' is being used to indicate the interface{} type or to export the underlying Go type as an interface{}. 'S' is used to refer to slice types, 'M' refers to map types, 'A' refers to string types, 'I' ints types, 'R' rune types and combinations may be used to indicate complex types. The documentation will always call out what exactly they mean, but the function name may be cryptic until understood.
Summary of Types ¶
• Char • FloatSlice • IntSlice • InterSlice • Object • RefSlice • Str • StringSlice • StringMap
Index ¶
- Variables
- func B(obj interface{}) bool
- func DeReference(obj interface{}) interface{}
- func EitherStr(first, second string) string
- func ExB(exp bool) bool
- func IdxFromSelector(selector string, size int) (i int, k, v string, err error)
- func MergeStringMap(a, b map[string]interface{}, selector ...string) map[string]interface{}
- func R(obj interface{}) rune
- func Range(min, max int) []int
- func Reference(obj interface{}) interface{}
- func SetOnEmpty(result *string, value string) string
- func SetOnFalseB(result *bool, value, exp bool) bool
- func SetOnTrueA(result *string, value string, exp bool) string
- func SetOnTrueB(result *bool, value, exp bool) bool
- func ToBoolE(obj interface{}) (val bool, err error)
- func ToDuration(obj interface{}) (val time.Duration)
- func ToDurationE(obj interface{}) (val time.Duration, err error)
- func ToFloat32(obj interface{}) float32
- func ToFloat32E(obj interface{}) (val float32, err error)
- func ToFloat64(obj interface{}) float64
- func ToFloat64E(obj interface{}) (val float64, err error)
- func ToInt(obj interface{}) int
- func ToInt16(obj interface{}) int16
- func ToInt16E(obj interface{}) (val int16, err error)
- func ToInt32(obj interface{}) int32
- func ToInt32E(obj interface{}) (val int32, err error)
- func ToInt64(obj interface{}) int64
- func ToInt64E(obj interface{}) (val int64, err error)
- func ToInt8(obj interface{}) int8
- func ToInt8E(obj interface{}) (val int8, err error)
- func ToIntE(obj interface{}) (val int, err error)
- func ToInts(obj interface{}) []int
- func ToRune(obj interface{}) rune
- func ToString(obj interface{}) string
- func ToStringMapG(obj interface{}) map[string]interface{}
- func ToStringMapGE(obj interface{}) (val map[string]interface{}, err error)
- func ToStrs(obj interface{}) (val []string)
- func ToStrsE(obj interface{}) (val []string, err error)
- func ToTime(obj interface{}) time.Time
- func ToTimeE(obj interface{}) (val time.Time, err error)
- func ToUint(obj interface{}) uint
- func ToUint16(obj interface{}) uint16
- func ToUint16E(obj interface{}) (val uint16, err error)
- func ToUint32(obj interface{}) uint32
- func ToUint32E(obj interface{}) (val uint32, err error)
- func ToUint64(obj interface{}) uint64
- func ToUint64E(obj interface{}) (val uint64, err error)
- func ToUint8(obj interface{}) uint8
- func ToUint8E(obj interface{}) (val uint8, err error)
- func ToUintE(obj interface{}) (val uint, err error)
- func UseLocalTime(useLocal bool)
- func YAMLArray(obj interface{}) bool
- func YAMLCont(obj interface{}) bool
- func YAMLMap(obj interface{}) bool
- type Char
- type FloatMapBool
- type FloatSlice
- func (p *FloatSlice) A() string
- func (p *FloatSlice) All(elems ...interface{}) bool
- func (p *FloatSlice) AllS(slice interface{}) bool
- func (p *FloatSlice) Any(elems ...interface{}) bool
- func (p *FloatSlice) AnyS(slice interface{}) bool
- func (p *FloatSlice) AnyW(sel func(O) bool) bool
- func (p *FloatSlice) Append(elem interface{}) ISlice
- func (p *FloatSlice) AppendV(elems ...interface{}) ISlice
- func (p *FloatSlice) At(i int) (elem *Object)
- func (p *FloatSlice) Clear() ISlice
- func (p *FloatSlice) Concat(slice interface{}) (new ISlice)
- func (p *FloatSlice) ConcatM(slice interface{}) ISlice
- func (p *FloatSlice) Copy(indices ...int) (new ISlice)
- func (p *FloatSlice) Count(elem interface{}) (cnt int)
- func (p *FloatSlice) CountW(sel func(O) bool) (cnt int)
- func (p *FloatSlice) Drop(indices ...int) ISlice
- func (p *FloatSlice) DropAt(i int) ISlice
- func (p *FloatSlice) DropFirst() ISlice
- func (p *FloatSlice) DropFirstN(n int) ISlice
- func (p *FloatSlice) DropLast() ISlice
- func (p *FloatSlice) DropLastN(n int) ISlice
- func (p *FloatSlice) DropW(sel func(O) bool) ISlice
- func (p *FloatSlice) Each(action func(O)) ISlice
- func (p *FloatSlice) EachE(action func(O) error) (ISlice, error)
- func (p *FloatSlice) EachI(action func(int, O)) ISlice
- func (p *FloatSlice) EachIE(action func(int, O) error) (ISlice, error)
- func (p *FloatSlice) EachR(action func(O)) ISlice
- func (p *FloatSlice) EachRE(action func(O) error) (ISlice, error)
- func (p *FloatSlice) EachRI(action func(int, O)) ISlice
- func (p *FloatSlice) EachRIE(action func(int, O) error) (ISlice, error)
- func (p *FloatSlice) Empty() bool
- func (p *FloatSlice) First() (elem *Object)
- func (p *FloatSlice) FirstN(n int) ISlice
- func (p *FloatSlice) G() []float64
- func (p *FloatSlice) Index(elem interface{}) (loc int)
- func (p *FloatSlice) Insert(i int, obj interface{}) ISlice
- func (p *FloatSlice) InterSlice() bool
- func (p *FloatSlice) Join(separator ...string) (str *Object)
- func (p *FloatSlice) Last() (elem *Object)
- func (p *FloatSlice) LastN(n int) ISlice
- func (p *FloatSlice) Len() int
- func (p *FloatSlice) Less(i, j int) bool
- func (p *FloatSlice) Map(mod func(O) O) ISlice
- func (p *FloatSlice) Nil() bool
- func (p *FloatSlice) O() interface{}
- func (p *FloatSlice) Pair() (first, second *Object)
- func (p *FloatSlice) Pop() (elem *Object)
- func (p *FloatSlice) PopN(n int) (new ISlice)
- func (p *FloatSlice) Prepend(elem interface{}) ISlice
- func (p *FloatSlice) RefSlice() bool
- func (p *FloatSlice) Reverse() (new ISlice)
- func (p *FloatSlice) ReverseM() ISlice
- func (p *FloatSlice) S() (slice *StringSlice)
- func (p *FloatSlice) Select(sel func(O) bool) (new ISlice)
- func (p *FloatSlice) Set(i int, elems interface{}) ISlice
- func (p *FloatSlice) SetE(i int, elems interface{}) (ISlice, error)
- func (p *FloatSlice) Shift() (elem *Object)
- func (p *FloatSlice) ShiftN(n int) (new ISlice)
- func (p *FloatSlice) Single() bool
- func (p *FloatSlice) Slice(indices ...int) ISlice
- func (p *FloatSlice) Sort() (new ISlice)
- func (p *FloatSlice) SortM() ISlice
- func (p *FloatSlice) SortReverse() (new ISlice)
- func (p *FloatSlice) SortReverseM() ISlice
- func (p *FloatSlice) String() string
- func (p *FloatSlice) Swap(i, j int)
- func (p *FloatSlice) Take(indices ...int) (new ISlice)
- func (p *FloatSlice) TakeAt(i int) (elem *Object)
- func (p *FloatSlice) TakeW(sel func(O) bool) (new ISlice)
- func (p *FloatSlice) ToIntSlice() (slice *IntSlice)
- func (p *FloatSlice) ToInterSlice() (slice []interface{})
- func (p *FloatSlice) ToInts() (slice []int)
- func (p *FloatSlice) ToStringSlice() (slice *StringSlice)
- func (p *FloatSlice) ToStrs() (slice []string)
- func (p *FloatSlice) Union(slice interface{}) (new ISlice)
- func (p *FloatSlice) UnionM(slice interface{}) ISlice
- func (p *FloatSlice) Uniq() (new ISlice)
- func (p *FloatSlice) UniqM() ISlice
- type IF
- type IMap
- type ISlice
- type IntMapBool
- type IntSlice
- func (p *IntSlice) A() string
- func (p *IntSlice) All(elems ...interface{}) bool
- func (p *IntSlice) AllS(slice interface{}) bool
- func (p *IntSlice) Any(elems ...interface{}) bool
- func (p *IntSlice) AnyS(slice interface{}) bool
- func (p *IntSlice) AnyW(sel func(O) bool) bool
- func (p *IntSlice) Append(elem interface{}) ISlice
- func (p *IntSlice) AppendV(elems ...interface{}) ISlice
- func (p *IntSlice) At(i int) (elem *Object)
- func (p *IntSlice) Clear() ISlice
- func (p *IntSlice) Concat(slice interface{}) (new ISlice)
- func (p *IntSlice) ConcatM(slice interface{}) ISlice
- func (p *IntSlice) Copy(indices ...int) (new ISlice)
- func (p *IntSlice) Count(elem interface{}) (cnt int)
- func (p *IntSlice) CountW(sel func(O) bool) (cnt int)
- func (p *IntSlice) Drop(indices ...int) ISlice
- func (p *IntSlice) DropAt(i int) ISlice
- func (p *IntSlice) DropFirst() ISlice
- func (p *IntSlice) DropFirstN(n int) ISlice
- func (p *IntSlice) DropLast() ISlice
- func (p *IntSlice) DropLastN(n int) ISlice
- func (p *IntSlice) DropW(sel func(O) bool) ISlice
- func (p *IntSlice) Each(action func(O)) ISlice
- func (p *IntSlice) EachE(action func(O) error) (ISlice, error)
- func (p *IntSlice) EachI(action func(int, O)) ISlice
- func (p *IntSlice) EachIE(action func(int, O) error) (ISlice, error)
- func (p *IntSlice) EachR(action func(O)) ISlice
- func (p *IntSlice) EachRE(action func(O) error) (ISlice, error)
- func (p *IntSlice) EachRI(action func(int, O)) ISlice
- func (p *IntSlice) EachRIE(action func(int, O) error) (ISlice, error)
- func (p *IntSlice) Empty() bool
- func (p *IntSlice) First() (elem *Object)
- func (p *IntSlice) FirstN(n int) ISlice
- func (p *IntSlice) G() []int
- func (p *IntSlice) Index(elem interface{}) (loc int)
- func (p *IntSlice) Insert(i int, obj interface{}) ISlice
- func (p *IntSlice) InterSlice() bool
- func (p *IntSlice) Join(separator ...string) (str *Object)
- func (p *IntSlice) Last() (elem *Object)
- func (p *IntSlice) LastN(n int) ISlice
- func (p *IntSlice) Len() int
- func (p *IntSlice) Less(i, j int) bool
- func (p *IntSlice) Map(mod func(O) O) ISlice
- func (p *IntSlice) Nil() bool
- func (p *IntSlice) O() interface{}
- func (p *IntSlice) Pair() (first, second *Object)
- func (p *IntSlice) Pop() (elem *Object)
- func (p *IntSlice) PopN(n int) (new ISlice)
- func (p *IntSlice) Prepend(elem interface{}) ISlice
- func (p *IntSlice) RefSlice() bool
- func (p *IntSlice) Reverse() (new ISlice)
- func (p *IntSlice) ReverseM() ISlice
- func (p *IntSlice) S() (slice *StringSlice)
- func (p *IntSlice) Select(sel func(O) bool) (new ISlice)
- func (p *IntSlice) Set(i int, elems interface{}) ISlice
- func (p *IntSlice) SetE(i int, elems interface{}) (ISlice, error)
- func (p *IntSlice) Shift() (elem *Object)
- func (p *IntSlice) ShiftN(n int) (new ISlice)
- func (p *IntSlice) Single() bool
- func (p *IntSlice) Slice(indices ...int) ISlice
- func (p *IntSlice) Sort() (new ISlice)
- func (p *IntSlice) SortM() ISlice
- func (p *IntSlice) SortReverse() (new ISlice)
- func (p *IntSlice) SortReverseM() ISlice
- func (p *IntSlice) String() string
- func (p *IntSlice) Swap(i, j int)
- func (p *IntSlice) Take(indices ...int) (new ISlice)
- func (p *IntSlice) TakeAt(i int) (elem *Object)
- func (p *IntSlice) TakeW(sel func(O) bool) (new ISlice)
- func (p *IntSlice) ToIntSlice() (slice *IntSlice)
- func (p *IntSlice) ToInterSlice() (slice []interface{})
- func (p *IntSlice) ToInts() (slice []int)
- func (p *IntSlice) ToStringSlice() (slice *StringSlice)
- func (p *IntSlice) ToStrs() (slice []string)
- func (p *IntSlice) Union(slice interface{}) (new ISlice)
- func (p *IntSlice) UnionM(slice interface{}) ISlice
- func (p *IntSlice) Uniq() (new ISlice)
- func (p *IntSlice) UniqM() ISlice
- type InterSlice
- func (p *InterSlice) A() string
- func (p *InterSlice) All(elems ...interface{}) bool
- func (p *InterSlice) AllS(slice interface{}) bool
- func (p *InterSlice) Any(elems ...interface{}) bool
- func (p *InterSlice) AnyS(slice interface{}) bool
- func (p *InterSlice) AnyW(sel func(O) bool) bool
- func (p *InterSlice) Append(elem interface{}) ISlice
- func (p *InterSlice) AppendV(elems ...interface{}) ISlice
- func (p *InterSlice) At(i int) (elem *Object)
- func (p *InterSlice) Clear() ISlice
- func (p *InterSlice) Concat(slice interface{}) (new ISlice)
- func (p *InterSlice) ConcatM(slice interface{}) ISlice
- func (p *InterSlice) Copy(indices ...int) (new ISlice)
- func (p *InterSlice) Count(elem interface{}) (cnt int)
- func (p *InterSlice) CountW(sel func(O) bool) (cnt int)
- func (p *InterSlice) Drop(indices ...int) ISlice
- func (p *InterSlice) DropAt(i int) ISlice
- func (p *InterSlice) DropFirst() ISlice
- func (p *InterSlice) DropFirstN(n int) ISlice
- func (p *InterSlice) DropLast() ISlice
- func (p *InterSlice) DropLastN(n int) ISlice
- func (p *InterSlice) DropW(sel func(O) bool) ISlice
- func (p *InterSlice) Each(action func(O)) ISlice
- func (p *InterSlice) EachE(action func(O) error) (ISlice, error)
- func (p *InterSlice) EachI(action func(int, O)) ISlice
- func (p *InterSlice) EachIE(action func(int, O) error) (ISlice, error)
- func (p *InterSlice) EachR(action func(O)) ISlice
- func (p *InterSlice) EachRE(action func(O) error) (ISlice, error)
- func (p *InterSlice) EachRI(action func(int, O)) ISlice
- func (p *InterSlice) EachRIE(action func(int, O) error) (ISlice, error)
- func (p *InterSlice) Empty() bool
- func (p *InterSlice) First() (elem *Object)
- func (p *InterSlice) FirstN(n int) ISlice
- func (p *InterSlice) G() []interface{}
- func (p *InterSlice) Index(elem interface{}) (loc int)
- func (p *InterSlice) Insert(i int, obj interface{}) ISlice
- func (p *InterSlice) InterSlice() bool
- func (p *InterSlice) Join(separator ...string) (str *Object)
- func (p *InterSlice) Last() (elem *Object)
- func (p *InterSlice) LastN(n int) ISlice
- func (p *InterSlice) Len() int
- func (p *InterSlice) Less(i, j int) bool
- func (p *InterSlice) Map(mod func(O) O) ISlice
- func (p *InterSlice) Nil() bool
- func (p *InterSlice) O() interface{}
- func (p *InterSlice) Pair() (first, second *Object)
- func (p *InterSlice) Pop() (elem *Object)
- func (p *InterSlice) PopN(n int) (new ISlice)
- func (p *InterSlice) Prepend(elem interface{}) ISlice
- func (p *InterSlice) RefSlice() bool
- func (p *InterSlice) Reverse() (new ISlice)
- func (p *InterSlice) ReverseM() ISlice
- func (p *InterSlice) S() (slice *StringSlice)
- func (p *InterSlice) Select(sel func(O) bool) (new ISlice)
- func (p *InterSlice) Set(i int, elem interface{}) ISlice
- func (p *InterSlice) SetE(i int, elems interface{}) (ISlice, error)
- func (p *InterSlice) Shift() (elem *Object)
- func (p *InterSlice) ShiftN(n int) (new ISlice)
- func (p *InterSlice) Single() bool
- func (p *InterSlice) Slice(indices ...int) ISlice
- func (p *InterSlice) Sort() (new ISlice)
- func (p *InterSlice) SortM() ISlice
- func (p *InterSlice) SortReverse() (new ISlice)
- func (p *InterSlice) SortReverseM() ISlice
- func (p *InterSlice) String() string
- func (p *InterSlice) Swap(i, j int)
- func (p *InterSlice) Take(indices ...int) (new ISlice)
- func (p *InterSlice) TakeAt(i int) (elem *Object)
- func (p *InterSlice) TakeW(sel func(O) bool) (new ISlice)
- func (p *InterSlice) ToIntSlice() (slice *IntSlice)
- func (p *InterSlice) ToInterSlice() (slice []interface{})
- func (p *InterSlice) ToInts() (slice []int)
- func (p *InterSlice) ToStringSlice() (slice *StringSlice)
- func (p *InterSlice) ToStrs() (slice []string)
- func (p *InterSlice) Union(slice interface{}) (new ISlice)
- func (p *InterSlice) UnionM(slice interface{}) ISlice
- func (p *InterSlice) Uniq() (new ISlice)
- func (p *InterSlice) UniqM() ISlice
- type O
- type Object
- func (p *Object) A() string
- func (p *Object) C() *Char
- func (p *Object) M() *StringMap
- func (p *Object) MG() map[string]interface{}
- func (p *Object) Nil() bool
- func (p *Object) O() interface{}
- func (p *Object) Query(key string) *Object
- func (p *Object) QueryE(key string) (obj *Object, err error)
- func (p *Object) R() rune
- func (p *Object) S() *StringSlice
- func (p *Object) String() string
- func (p *Object) ToBool() bool
- func (p *Object) ToBoolE() (bool, error)
- func (p *Object) ToChar() *Char
- func (p *Object) ToDuration() time.Duration
- func (p *Object) ToDurationE() (time.Duration, error)
- func (p *Object) ToFloat32() float32
- func (p *Object) ToFloat32E() (float32, error)
- func (p *Object) ToFloat64() float64
- func (p *Object) ToFloat64E() (float64, error)
- func (p *Object) ToInt() int
- func (p *Object) ToInt16() int16
- func (p *Object) ToInt16E() (int16, error)
- func (p *Object) ToInt32() int32
- func (p *Object) ToInt32E() (int32, error)
- func (p *Object) ToInt64() int64
- func (p *Object) ToInt64E() (int64, error)
- func (p *Object) ToInt8() int8
- func (p *Object) ToInt8E() (int8, error)
- func (p *Object) ToIntE() (int, error)
- func (p *Object) ToIntSlice() *IntSlice
- func (p *Object) ToIntSliceE() (*IntSlice, error)
- func (p *Object) ToIntSliceG() []int
- func (p *Object) ToIntSliceGE() ([]int, error)
- func (p *Object) ToRune() rune
- func (p *Object) ToSliceOfMap() *SliceOfMap
- func (p *Object) ToSliceOfMapE() (*SliceOfMap, error)
- func (p *Object) ToSliceOfMapG() []map[string]interface{}
- func (p *Object) ToSliceOfMapGE() ([]map[string]interface{}, error)
- func (p *Object) ToStr() *Str
- func (p *Object) ToString() string
- func (p *Object) ToStringE() (string, error)
- func (p *Object) ToStringMap() *StringMap
- func (p *Object) ToStringMapE() (*StringMap, error)
- func (p *Object) ToStringMapG() map[string]interface{}
- func (p *Object) ToStringMapGE() (map[string]interface{}, error)
- func (p *Object) ToStringSlice() *StringSlice
- func (p *Object) ToStringSliceE() (*StringSlice, error)
- func (p *Object) ToStrs() []string
- func (p *Object) ToStrsE() ([]string, error)
- func (p *Object) ToTime() time.Time
- func (p *Object) ToTimeE() (time.Time, error)
- func (p *Object) ToUint() uint
- func (p *Object) ToUint16() uint16
- func (p *Object) ToUint16E() (uint16, error)
- func (p *Object) ToUint32() uint32
- func (p *Object) ToUint32E() (uint32, error)
- func (p *Object) ToUint64() uint64
- func (p *Object) ToUint64E() (uint64, error)
- func (p *Object) ToUint8() uint8
- func (p *Object) ToUint8E() (uint8, error)
- func (p *Object) ToUintE() (uint, error)
- type RefSlice
- func (p *RefSlice) A() string
- func (p *RefSlice) All(elems ...interface{}) bool
- func (p *RefSlice) AllS(slice interface{}) bool
- func (p *RefSlice) Any(elems ...interface{}) bool
- func (p *RefSlice) AnyS(slice interface{}) bool
- func (p *RefSlice) AnyW(sel func(O) bool) bool
- func (p *RefSlice) Append(elem interface{}) ISlice
- func (p *RefSlice) AppendV(elems ...interface{}) ISlice
- func (p *RefSlice) At(i int) (elem *Object)
- func (p *RefSlice) Clear() ISlice
- func (p *RefSlice) Concat(slice interface{}) (new ISlice)
- func (p *RefSlice) ConcatM(slice interface{}) ISlice
- func (p *RefSlice) Copy(indices ...int) (new ISlice)
- func (p *RefSlice) Count(elem interface{}) (cnt int)
- func (p *RefSlice) CountW(sel func(O) bool) (cnt int)
- func (p *RefSlice) Drop(indices ...int) ISlice
- func (p *RefSlice) DropAt(i int) ISlice
- func (p *RefSlice) DropFirst() ISlice
- func (p *RefSlice) DropFirstN(n int) ISlice
- func (p *RefSlice) DropLast() ISlice
- func (p *RefSlice) DropLastN(n int) ISlice
- func (p *RefSlice) DropW(sel func(O) bool) ISlice
- func (p *RefSlice) Each(action func(O)) ISlice
- func (p *RefSlice) EachE(action func(O) error) (ISlice, error)
- func (p *RefSlice) EachI(action func(int, O)) ISlice
- func (p *RefSlice) EachIE(action func(int, O) error) (ISlice, error)
- func (p *RefSlice) EachR(action func(O)) ISlice
- func (p *RefSlice) EachRE(action func(O) error) (ISlice, error)
- func (p *RefSlice) EachRI(action func(int, O)) ISlice
- func (p *RefSlice) EachRIE(action func(int, O) error) (ISlice, error)
- func (p *RefSlice) Empty() bool
- func (p *RefSlice) First() (elem *Object)
- func (p *RefSlice) FirstN(n int) ISlice
- func (p *RefSlice) Index(elem interface{}) (loc int)
- func (p *RefSlice) Insert(i int, elem interface{}) ISlice
- func (p *RefSlice) InsertS(i int, slice interface{}) ISlice
- func (p *RefSlice) InterSlice() bool
- func (p *RefSlice) Join(separator ...string) (str *Object)
- func (p *RefSlice) Last() (elem *Object)
- func (p *RefSlice) LastN(n int) ISlice
- func (p *RefSlice) Len() int
- func (p *RefSlice) Less(i, j int) bool
- func (p *RefSlice) Map(mod func(O) O) ISlice
- func (p *RefSlice) Nil() bool
- func (p *RefSlice) O() interface{}
- func (p *RefSlice) Pair() (first, second *Object)
- func (p *RefSlice) Pop() (elem *Object)
- func (p *RefSlice) PopN(n int) (new ISlice)
- func (p *RefSlice) Prepend(elem interface{}) ISlice
- func (p *RefSlice) RefSlice() bool
- func (p *RefSlice) Reverse() (new ISlice)
- func (p *RefSlice) ReverseM() ISlice
- func (p *RefSlice) S() (slice *StringSlice)
- func (p *RefSlice) Select(sel func(O) bool) (new ISlice)
- func (p *RefSlice) Set(i int, elem interface{}) ISlice
- func (p *RefSlice) SetE(i int, elem interface{}) (ISlice, error)
- func (p *RefSlice) Shift() (elem *Object)
- func (p *RefSlice) ShiftN(n int) (new ISlice)
- func (p *RefSlice) Single() bool
- func (p *RefSlice) Slice(indices ...int) ISlice
- func (p *RefSlice) Sort() (new ISlice)
- func (p *RefSlice) SortM() ISlice
- func (p *RefSlice) SortReverse() (new ISlice)
- func (p *RefSlice) SortReverseM() ISlice
- func (p *RefSlice) String() string
- func (p *RefSlice) Swap(i, j int)
- func (p *RefSlice) Take(indices ...int) (new ISlice)
- func (p *RefSlice) TakeAt(i int) (elem *Object)
- func (p *RefSlice) TakeW(sel func(O) bool) (new ISlice)
- func (p *RefSlice) ToIntSlice() (slice *IntSlice)
- func (p *RefSlice) ToInterSlice() (slice []interface{})
- func (p *RefSlice) ToInts() (slice []int)
- func (p *RefSlice) ToStringSlice() (slice *StringSlice)
- func (p *RefSlice) ToStrs() (slice []string)
- func (p *RefSlice) Union(slice interface{}) (new ISlice)
- func (p *RefSlice) UnionM(slice interface{}) ISlice
- func (p *RefSlice) Uniq() (new ISlice)
- func (p *RefSlice) UniqM() ISlice
- type RuneMapBool
- type SliceOfMap
- func (p *SliceOfMap) A() string
- func (p *SliceOfMap) All(elems ...interface{}) bool
- func (p *SliceOfMap) AllS(slice interface{}) bool
- func (p *SliceOfMap) Any(elems ...interface{}) bool
- func (p *SliceOfMap) AnyS(slice interface{}) bool
- func (p *SliceOfMap) AnyW(sel func(O) bool) bool
- func (p *SliceOfMap) Append(elem interface{}) ISlice
- func (p *SliceOfMap) AppendV(elems ...interface{}) ISlice
- func (p *SliceOfMap) At(i int) (elem *Object)
- func (p *SliceOfMap) Clear() ISlice
- func (p *SliceOfMap) Concat(slice interface{}) (new ISlice)
- func (p *SliceOfMap) ConcatM(slice interface{}) ISlice
- func (p *SliceOfMap) Copy(indices ...int) (new ISlice)
- func (p *SliceOfMap) Count(key interface{}) (cnt int)
- func (p *SliceOfMap) CountW(sel func(O) bool) (cnt int)
- func (p *SliceOfMap) Drop(indices ...int) ISlice
- func (p *SliceOfMap) DropAt(i int) ISlice
- func (p *SliceOfMap) DropFirst() ISlice
- func (p *SliceOfMap) DropFirstN(n int) ISlice
- func (p *SliceOfMap) DropLast() ISlice
- func (p *SliceOfMap) DropLastN(n int) ISlice
- func (p *SliceOfMap) DropW(sel func(O) bool) ISlice
- func (p *SliceOfMap) Each(action func(O)) ISlice
- func (p *SliceOfMap) EachE(action func(O) error) (ISlice, error)
- func (p *SliceOfMap) EachI(action func(int, O)) ISlice
- func (p *SliceOfMap) EachIE(action func(int, O) error) (ISlice, error)
- func (p *SliceOfMap) EachR(action func(O)) ISlice
- func (p *SliceOfMap) EachRE(action func(O) error) (ISlice, error)
- func (p *SliceOfMap) EachRI(action func(int, O)) ISlice
- func (p *SliceOfMap) EachRIE(action func(int, O) error) (ISlice, error)
- func (p *SliceOfMap) Empty() bool
- func (p *SliceOfMap) First() (elem *Object)
- func (p *SliceOfMap) FirstN(n int) ISlice
- func (p *SliceOfMap) G() []map[string]interface{}
- func (p *SliceOfMap) Index(elem interface{}) (loc int)
- func (p *SliceOfMap) Insert(i int, obj interface{}) ISlice
- func (p *SliceOfMap) InterSlice() bool
- func (p *SliceOfMap) Join(separator ...string) (str *Object)
- func (p *SliceOfMap) Last() (elem *Object)
- func (p *SliceOfMap) LastN(n int) ISlice
- func (p *SliceOfMap) Len() int
- func (p *SliceOfMap) Less(i, j int) bool
- func (p *SliceOfMap) Map(mod func(O) O) ISlice
- func (p *SliceOfMap) Nil() bool
- func (p *SliceOfMap) O() interface{}
- func (p *SliceOfMap) Pair() (first, second *Object)
- func (p *SliceOfMap) Pop() (elem *Object)
- func (p *SliceOfMap) PopN(n int) (new ISlice)
- func (p *SliceOfMap) Prepend(elem interface{}) ISlice
- func (p *SliceOfMap) RefSlice() bool
- func (p *SliceOfMap) Reverse() (new ISlice)
- func (p *SliceOfMap) ReverseM() ISlice
- func (p *SliceOfMap) S() (slice *StringSlice)
- func (p *SliceOfMap) Select(sel func(O) bool) (new ISlice)
- func (p *SliceOfMap) Set(i int, elem interface{}) ISlice
- func (p *SliceOfMap) SetE(i int, elems interface{}) (slice ISlice, err error)
- func (p *SliceOfMap) Shift() (elem *Object)
- func (p *SliceOfMap) ShiftN(n int) (new ISlice)
- func (p *SliceOfMap) Single() bool
- func (p *SliceOfMap) Slice(indices ...int) ISlice
- func (p *SliceOfMap) Sort() (new ISlice)
- func (p *SliceOfMap) SortM() ISlice
- func (p *SliceOfMap) SortReverse() (new ISlice)
- func (p *SliceOfMap) SortReverseM() ISlice
- func (p *SliceOfMap) String() string
- func (p *SliceOfMap) Swap(i, j int)
- func (p *SliceOfMap) Take(indices ...int) (new ISlice)
- func (p *SliceOfMap) TakeAt(i int) (elem *Object)
- func (p *SliceOfMap) TakeW(sel func(O) bool) (new ISlice)
- func (p *SliceOfMap) ToIntSlice() (slice *IntSlice)
- func (p *SliceOfMap) ToInterSlice() (slice []interface{})
- func (p *SliceOfMap) ToInts() (slice []int)
- func (p *SliceOfMap) ToStringSlice() (slice *StringSlice)
- func (p *SliceOfMap) ToStrs() (slice []string)
- func (p *SliceOfMap) Union(slice interface{}) (new ISlice)
- func (p *SliceOfMap) UnionM(slice interface{}) ISlice
- func (p *SliceOfMap) Uniq() (new ISlice)
- func (p *SliceOfMap) UniqM() ISlice
- type Str
- func (p *Str) A() string
- func (p *Str) All(elems ...interface{}) bool
- func (p *Str) AllS(slice interface{}) bool
- func (p *Str) Any(elems ...interface{}) bool
- func (p *Str) AnyS(slice interface{}) bool
- func (p *Str) AnyW(sel func(O) bool) bool
- func (p *Str) Append(elem interface{}) ISlice
- func (p *Str) AppendV(elems ...interface{}) ISlice
- func (p *Str) Ascii() *Str
- func (p *Str) AsciiA() string
- func (p *Str) AsciiOnly() bool
- func (p *Str) At(i int) (elem *Object)
- func (p *Str) B() []byte
- func (p *Str) C() *Char
- func (p *Str) Clear() ISlice
- func (p *Str) Concat(slice interface{}) (new ISlice)
- func (p *Str) ConcatA(str interface{}) string
- func (p *Str) ConcatM(slice interface{}) ISlice
- func (p *Str) Contains(str string) bool
- func (p *Str) ContainsAny(chars string) bool
- func (p *Str) ContainsRune(r rune) bool
- func (p *Str) Copy(indices ...int) (new ISlice)
- func (p *Str) CopyA(indices ...int) (new string)
- func (p *Str) Count(elem interface{}) (cnt int)
- func (p *Str) CountW(sel func(O) bool) (cnt int)
- func (p *Str) Drop(indices ...int) ISlice
- func (p *Str) DropAt(i int) ISlice
- func (p *Str) DropFirst() ISlice
- func (p *Str) DropFirstN(n int) ISlice
- func (p *Str) DropLast() ISlice
- func (p *Str) DropLastN(n int) ISlice
- func (p *Str) DropW(sel func(O) bool) ISlice
- func (p *Str) Each(action func(O)) ISlice
- func (p *Str) EachE(action func(O) error) (ISlice, error)
- func (p *Str) EachI(action func(int, O)) ISlice
- func (p *Str) EachIE(action func(int, O) error) (ISlice, error)
- func (p *Str) EachR(action func(O)) ISlice
- func (p *Str) EachRE(action func(O) error) (ISlice, error)
- func (p *Str) EachRI(action func(int, O)) ISlice
- func (p *Str) EachRIE(action func(int, O) error) (ISlice, error)
- func (p *Str) Empty() bool
- func (p *Str) Equal(val interface{}) bool
- func (p *Str) Fields() (new *StringSlice)
- func (p *Str) FieldsW(f func(rune) bool) (new *StringSlice)
- func (p *Str) First() (elem *Object)
- func (p *Str) FirstN(n int) ISlice
- func (p *Str) G() string
- func (p *Str) HasAnyPrefix(prefixes interface{}) bool
- func (p *Str) HasAnyPrefixV(prefixes ...interface{}) bool
- func (p *Str) HasAnySuffix(prefixes interface{}) bool
- func (p *Str) HasAnySuffixV(prefixes ...interface{}) bool
- func (p *Str) HasPrefix(prefix interface{}) bool
- func (p *Str) HasSuffix(prefix interface{}) bool
- func (p *Str) Index(substr interface{}) (loc int)
- func (p *Str) IndexAny(elems interface{}) (loc int)
- func (p *Str) IndexChar(char interface{}) (loc int)
- func (p *Str) Insert(i int, obj interface{}) ISlice
- func (p *Str) InterSlice() bool
- func (p *Str) Join(separator ...string) (str *Object)
- func (p *Str) Last() (elem *Object)
- func (p *Str) LastIndex(substr interface{}) (loc int)
- func (p *Str) LastIndexAny(elems interface{}) (loc int)
- func (p *Str) LastIndexChar(char interface{}) (loc int)
- func (p *Str) LastN(n int) ISlice
- func (p *Str) Len() int
- func (p *Str) Less(i, j int) bool
- func (p *Str) Map(mod func(O) O) ISlice
- func (p *Str) Nil() bool
- func (p *Str) O() interface{}
- func (p *Str) Pair() (first, second *Object)
- func (p *Str) Pop() (elem *Object)
- func (p *Str) PopN(n int) (new ISlice)
- func (p *Str) Prepend(elem interface{}) ISlice
- func (p *Str) RefSlice() bool
- func (p *Str) Replace(old, new interface{}, n int) *Str
- func (p *Str) ReplaceAll(old, new interface{}) *Str
- func (p *Str) Reverse() (new ISlice)
- func (p *Str) ReverseM() ISlice
- func (p *Str) S() (slice *StringSlice)
- func (p *Str) Select(sel func(O) bool) (new ISlice)
- func (p *Str) Set(i int, elem interface{}) ISlice
- func (p *Str) SetE(i int, elems interface{}) (ISlice, error)
- func (p *Str) Shift() (elem *Object)
- func (p *Str) ShiftN(n int) (new ISlice)
- func (p *Str) Single() bool
- func (p *Str) Slice(indices ...int) ISlice
- func (p *Str) Sort() (new ISlice)
- func (p *Str) SortM() ISlice
- func (p *Str) SortReverse() (new ISlice)
- func (p *Str) SortReverseM() ISlice
- func (p *Str) Split(separator ...string) (slice *StringSlice)
- func (p *Str) SplitAfter(separator ...string) (slice *StringSlice)
- func (p *Str) SplitEscape(separator string, escape ...string) (slice *StringSlice)
- func (p *Str) SplitQuotes() (slice *StringSlice, err error)
- func (p *Str) String() string
- func (p *Str) Swap(i, j int)
- func (p *Str) Take(indices ...int) (new ISlice)
- func (p *Str) TakeAt(i int) (elem *Object)
- func (p *Str) TakeW(sel func(O) bool) (new ISlice)
- func (p *Str) Title() (new *Str)
- func (p *Str) ToIntSlice() (slice *IntSlice)
- func (p *Str) ToInterSlice() (slice []interface{})
- func (p *Str) ToInts() (slice []int)
- func (p *Str) ToLower() (new *Str)
- func (p *Str) ToStringSlice() (slice *StringSlice)
- func (p *Str) ToStrs() (slice []string)
- func (p *Str) ToUpper() (new *Str)
- func (p *Str) Trim(cutset ...interface{}) (new *Str)
- func (p *Str) TrimFunc(f func(rune) bool) (new *Str)
- func (p *Str) TrimLeft(cutset ...interface{}) (new *Str)
- func (p *Str) TrimLeftFunc(f func(rune) bool) (new *Str)
- func (p *Str) TrimPrefix(prefix interface{}) (new *Str)
- func (p *Str) TrimRight(cutset ...interface{}) (new *Str)
- func (p *Str) TrimRightFunc(f func(rune) bool) (new *Str)
- func (p *Str) TrimSuffix(suffix interface{}) (new *Str)
- func (p *Str) Union(slice interface{}) (new ISlice)
- func (p *Str) UnionM(slice interface{}) ISlice
- func (p *Str) Uniq() (new ISlice)
- func (p *Str) UniqM() ISlice
- type StringMap
- func LoadJSON(filepath string) (m *StringMap)
- func LoadJSONE(filepath string) (m *StringMap, err error)
- func LoadYAML(filepath string) (m *StringMap)
- func LoadYAMLE(filepath string) (m *StringMap, err error)
- func M() *StringMap
- func MV(m ...interface{}) *StringMap
- func Map(obj interface{}) (new *StringMap)
- func NewStringMap(obj interface{}) *StringMap
- func NewStringMapV(m ...interface{}) *StringMap
- func ToStringMap(obj interface{}) *StringMap
- func ToStringMapE(obj interface{}) (val *StringMap, err error)
- func (p *StringMap) Add(key, val interface{}) *StringMap
- func (p *StringMap) Any(keys ...interface{}) bool
- func (p *StringMap) At(i int) (key string, val *Object)
- func (p *StringMap) Clear() IMap
- func (p *StringMap) Copy(keys ...interface{}) (new IMap)
- func (p *StringMap) Delete(key interface{}) (val *Object)
- func (p *StringMap) DeleteM(key interface{}) IMap
- func (p *StringMap) Dump() (pretty string)
- func (p *StringMap) Exists(key interface{}) bool
- func (p *StringMap) G() map[string]interface{}
- func (p *StringMap) GE() (val map[string]interface{}, err error)
- func (p *StringMap) Generic() bool
- func (p *StringMap) Get(key interface{}) (val *Object)
- func (p *StringMap) Keys() ISlice
- func (p *StringMap) Len() int
- func (p *StringMap) M() (m *StringMap)
- func (p *StringMap) MG() (m map[string]interface{})
- func (p *StringMap) Merge(m IMap, selector ...string) IMap
- func (p *StringMap) MergeG(m IMap, selector ...string) map[string]interface{}
- func (p *StringMap) O() interface{}
- func (p *StringMap) Query(selector string, params ...interface{}) (val *Object)
- func (p *StringMap) QueryE(selector string, params ...interface{}) (val *Object, err error)
- func (p *StringMap) Remove(selector string, params ...interface{}) IMap
- func (p *StringMap) RemoveE(selector string, params ...interface{}) (m IMap, err error)
- func (p *StringMap) Set(key, val interface{}) (new bool)
- func (p *StringMap) SetM(key, val interface{}) IMap
- func (p *StringMap) ToStringMap() (m *StringMap)
- func (p *StringMap) ToStringMapG() (m map[string]interface{})
- func (p *StringMap) Update(selector string, val interface{}) IMap
- func (p *StringMap) UpdateE(selector string, val interface{}) (m IMap, err error)
- func (p *StringMap) WriteJSON(filename string) (err error)
- func (p *StringMap) WriteYAML(filename string) (err error)
- func (p *StringMap) YAML() (data string)
- func (p *StringMap) YAMLE() (data string, err error)
- type StringMapBool
- type StringSlice
- func KeysFromSelector(selector string, params ...interface{}) (keys *StringSlice, err error)
- func NewStringSlice(slice interface{}) *StringSlice
- func NewStringSliceV(elems ...interface{}) *StringSlice
- func S(obj interface{}) *StringSlice
- func SV(elems ...interface{}) (new *StringSlice)
- func ToStringSlice(obj interface{}) *StringSlice
- func ToStringSliceE(obj interface{}) (val *StringSlice, err error)
- func (p *StringSlice) A() string
- func (p *StringSlice) All(elems ...interface{}) bool
- func (p *StringSlice) AllS(slice interface{}) bool
- func (p *StringSlice) Any(elems ...interface{}) bool
- func (p *StringSlice) AnyS(slice interface{}) bool
- func (p *StringSlice) AnyW(sel func(O) bool) bool
- func (p *StringSlice) Append(elem interface{}) ISlice
- func (p *StringSlice) AppendV(elems ...interface{}) ISlice
- func (p *StringSlice) At(i int) (elem *Object)
- func (p *StringSlice) Clear() ISlice
- func (p *StringSlice) Concat(slice interface{}) (new ISlice)
- func (p *StringSlice) ConcatM(slice interface{}) ISlice
- func (p *StringSlice) Copy(indices ...int) (new ISlice)
- func (p *StringSlice) Count(elem interface{}) (cnt int)
- func (p *StringSlice) CountW(sel func(O) bool) (cnt int)
- func (p *StringSlice) Drop(indices ...int) ISlice
- func (p *StringSlice) DropAt(i int) ISlice
- func (p *StringSlice) DropFirst() ISlice
- func (p *StringSlice) DropFirstN(n int) ISlice
- func (p *StringSlice) DropFirstW(sel func(O) bool) ISlice
- func (p *StringSlice) DropLast() ISlice
- func (p *StringSlice) DropLastN(n int) ISlice
- func (p *StringSlice) DropW(sel func(O) bool) ISlice
- func (p *StringSlice) Each(action func(O)) ISlice
- func (p *StringSlice) EachE(action func(O) error) (ISlice, error)
- func (p *StringSlice) EachI(action func(int, O)) ISlice
- func (p *StringSlice) EachIE(action func(int, O) error) (ISlice, error)
- func (p *StringSlice) EachR(action func(O)) ISlice
- func (p *StringSlice) EachRE(action func(O) error) (ISlice, error)
- func (p *StringSlice) EachRI(action func(int, O)) ISlice
- func (p *StringSlice) EachRIE(action func(int, O) error) (ISlice, error)
- func (p *StringSlice) Empty() bool
- func (p *StringSlice) First() (elem *Object)
- func (p *StringSlice) FirstN(n int) ISlice
- func (p *StringSlice) FirstW(sel func(O) bool) (elem *Object)
- func (p *StringSlice) G() []string
- func (p *StringSlice) Index(elem interface{}) (loc int)
- func (p *StringSlice) Insert(i int, obj interface{}) ISlice
- func (p *StringSlice) InterSlice() bool
- func (p *StringSlice) Join(separator ...string) (str *Object)
- func (p *StringSlice) Last() (elem *Object)
- func (p *StringSlice) LastN(n int) ISlice
- func (p *StringSlice) Len() int
- func (p *StringSlice) Less(i, j int) bool
- func (p *StringSlice) Map(mod func(O) O) ISlice
- func (p *StringSlice) Nil() bool
- func (p *StringSlice) O() interface{}
- func (p *StringSlice) Pair() (first, second *Object)
- func (p *StringSlice) Pop() (elem *Object)
- func (p *StringSlice) PopN(n int) (new ISlice)
- func (p *StringSlice) Prepend(elem interface{}) ISlice
- func (p *StringSlice) RefSlice() bool
- func (p *StringSlice) Reverse() (new ISlice)
- func (p *StringSlice) ReverseM() ISlice
- func (p *StringSlice) S() (slice *StringSlice)
- func (p *StringSlice) Select(sel func(O) bool) (new ISlice)
- func (p *StringSlice) Set(i int, elem interface{}) ISlice
- func (p *StringSlice) SetE(i int, elems interface{}) (ISlice, error)
- func (p *StringSlice) Shift() (elem *Object)
- func (p *StringSlice) ShiftN(n int) (new ISlice)
- func (p *StringSlice) Single() bool
- func (p *StringSlice) Slice(indices ...int) ISlice
- func (p *StringSlice) Sort() (new ISlice)
- func (p *StringSlice) SortM() ISlice
- func (p *StringSlice) SortReverse() (new ISlice)
- func (p *StringSlice) SortReverseM() ISlice
- func (p *StringSlice) String() string
- func (p *StringSlice) Swap(i, j int)
- func (p *StringSlice) Take(indices ...int) (new ISlice)
- func (p *StringSlice) TakeAt(i int) (elem *Object)
- func (p *StringSlice) TakeW(sel func(O) bool) (new ISlice)
- func (p *StringSlice) ToIntSlice() (slice *IntSlice)
- func (p *StringSlice) ToInterSlice() (slice []interface{})
- func (p *StringSlice) ToInts() (slice []int)
- func (p *StringSlice) ToStringSlice() (slice *StringSlice)
- func (p *StringSlice) ToStrs() (slice []string)
- func (p *StringSlice) Union(slice interface{}) (new ISlice)
- func (p *StringSlice) UnionM(slice interface{}) ISlice
- func (p *StringSlice) Uniq() (new ISlice)
- func (p *StringSlice) UniqM() ISlice
- Bugs
Examples ¶
- A
- Char.Equal
- Char.Less
- Char.String
- DeReference
- EitherStr
- FloatSlice.All (Contains)
- FloatSlice.All (ContainsAll)
- FloatSlice.All (Empty)
- FloatSlice.All (NotEmpty)
- FloatSlice.AllS
- FloatSlice.Any (Contains)
- FloatSlice.Any (ContainsAny)
- FloatSlice.Any (Empty)
- FloatSlice.Any (NotEmpty)
- FloatSlice.AnyS
- FloatSlice.AnyW
- FloatSlice.Append
- FloatSlice.AppendV
- FloatSlice.At
- FloatSlice.Clear
- FloatSlice.Concat
- FloatSlice.ConcatM
- FloatSlice.Copy
- FloatSlice.Count
- FloatSlice.CountW
- FloatSlice.Drop
- FloatSlice.DropAt
- FloatSlice.DropFirst
- FloatSlice.DropFirstN
- FloatSlice.DropLast
- FloatSlice.DropLastN
- FloatSlice.Each
- FloatSlice.EachE
- FloatSlice.EachI
- FloatSlice.EachIE
- FloatSlice.EachR
- FloatSlice.EachRE
- FloatSlice.EachRI
- FloatSlice.EachRIE
- FloatSlice.Empty
- FloatSlice.First
- FloatSlice.G
- FloatSlice.Index
- FloatSlice.Insert
- FloatSlice.Join
- FloatSlice.Last
- FloatSlice.LastN
- FloatSlice.Len
- FloatSlice.Less
- FloatSlice.Nil
- FloatSlice.O
- FloatSlice.Pair
- FloatSlice.Pop
- FloatSlice.PopN
- FloatSlice.Prepend
- FloatSlice.Reverse
- FloatSlice.ReverseM
- FloatSlice.Select
- FloatSlice.Set
- FloatSlice.SetE
- FloatSlice.Shift
- FloatSlice.ShiftN
- FloatSlice.Slice
- FloatSlice.Sort
- FloatSlice.SortM
- FloatSlice.SortReverse
- FloatSlice.SortReverseM
- FloatSlice.String
- FloatSlice.Swap
- FloatSlice.Take
- FloatSlice.TakeAt
- FloatSlice.Union
- FloatSlice.UnionM
- FloatSlice.Uniq
- FloatSlice.UniqM
- IntSlice.All (Contains)
- IntSlice.All (ContainsAll)
- IntSlice.All (Empty)
- IntSlice.All (NotEmpty)
- IntSlice.AllS
- IntSlice.Any (Contains)
- IntSlice.Any (ContainsAny)
- IntSlice.Any (Empty)
- IntSlice.Any (NotEmpty)
- IntSlice.AnyS
- IntSlice.AnyW
- IntSlice.Append
- IntSlice.AppendV
- IntSlice.At
- IntSlice.Clear
- IntSlice.Concat
- IntSlice.ConcatM
- IntSlice.Copy
- IntSlice.Count
- IntSlice.CountW
- IntSlice.Drop
- IntSlice.DropAt
- IntSlice.DropFirst
- IntSlice.DropFirstN
- IntSlice.DropLast
- IntSlice.DropLastN
- IntSlice.DropW
- IntSlice.Each
- IntSlice.EachE
- IntSlice.EachI
- IntSlice.EachIE
- IntSlice.EachR
- IntSlice.EachRE
- IntSlice.EachRI
- IntSlice.EachRIE
- IntSlice.Empty
- IntSlice.First
- IntSlice.FirstN
- IntSlice.G
- IntSlice.Index
- IntSlice.Insert
- IntSlice.Join
- IntSlice.Last
- IntSlice.LastN
- IntSlice.Len
- IntSlice.Less
- IntSlice.Nil
- IntSlice.O
- IntSlice.Pair
- IntSlice.Pop
- IntSlice.PopN
- IntSlice.Prepend
- IntSlice.Reverse
- IntSlice.ReverseM
- IntSlice.Select
- IntSlice.Set
- IntSlice.SetE
- IntSlice.Shift
- IntSlice.ShiftN
- IntSlice.Single
- IntSlice.Slice
- IntSlice.Sort
- IntSlice.SortM
- IntSlice.SortReverse
- IntSlice.SortReverseM
- IntSlice.String
- IntSlice.Swap
- IntSlice.Take
- IntSlice.TakeAt
- IntSlice.TakeW
- IntSlice.Union
- IntSlice.UnionM
- IntSlice.Uniq
- IntSlice.UniqM
- InterSlice.All (Contains)
- InterSlice.All (ContainsAll)
- InterSlice.All (Empty)
- InterSlice.All (NotEmpty)
- InterSlice.AllS
- InterSlice.Any (Contains)
- InterSlice.Any (ContainsAny)
- InterSlice.Any (Empty)
- InterSlice.Any (NotEmpty)
- InterSlice.AnyS
- InterSlice.AnyW
- InterSlice.Append
- InterSlice.AppendV
- InterSlice.At
- InterSlice.Clear
- InterSlice.Concat
- InterSlice.ConcatM
- InterSlice.Copy
- InterSlice.Count
- InterSlice.CountW
- InterSlice.Drop
- InterSlice.DropAt
- InterSlice.DropFirst
- InterSlice.DropFirstN
- InterSlice.DropLast
- InterSlice.DropLastN
- InterSlice.DropW
- InterSlice.Each
- InterSlice.EachE
- InterSlice.EachI
- InterSlice.EachIE
- InterSlice.EachR
- InterSlice.EachRE
- InterSlice.EachRI
- InterSlice.EachRIE
- InterSlice.Empty
- InterSlice.First
- InterSlice.FirstN
- InterSlice.Index
- InterSlice.Insert
- InterSlice.InterSlice
- InterSlice.Join
- InterSlice.Last
- InterSlice.LastN
- InterSlice.Less
- InterSlice.Map
- InterSlice.Pair
- InterSlice.Pop
- InterSlice.PopN
- InterSlice.Prepend
- InterSlice.Reverse
- InterSlice.ReverseM
- InterSlice.Select
- InterSlice.Set
- InterSlice.SetE
- InterSlice.Shift
- InterSlice.ShiftN
- InterSlice.Single
- InterSlice.Slice
- InterSlice.Sort
- InterSlice.SortM
- InterSlice.SortReverse
- InterSlice.SortReverseM
- InterSlice.String
- InterSlice.Swap
- InterSlice.Take
- InterSlice.TakeAt
- InterSlice.TakeW
- Map
- MergeStringMap
- NewFloatSlice
- NewFloatSliceV (Empty)
- NewFloatSliceV (Variadic)
- NewIntSlice
- NewIntSliceV (Empty)
- NewIntSliceV (Variadic)
- NewInterSlice
- NewInterSliceV (Empty)
- NewInterSliceV (Variadic)
- NewRefSlice
- NewRefSliceV (Empty)
- NewRefSliceV (Variadic)
- NewSliceOfMap
- NewSliceOfMapV (Empty)
- NewSliceOfMapV (Variadic)
- NewStr
- NewStringMap
- NewStringMapV
- NewStringSlice
- NewStringSliceV (Empty)
- NewStringSliceV (Variadic)
- RefSlice.Any (Contains)
- RefSlice.Any (ContainsAny)
- RefSlice.Any (Empty)
- RefSlice.Any (NotEmpty)
- RefSlice.AnyS
- RefSlice.AnyW
- RefSlice.Append
- RefSlice.AppendV
- RefSlice.At
- RefSlice.Clear
- RefSlice.Concat
- RefSlice.ConcatM
- RefSlice.Copy
- RefSlice.Count
- RefSlice.CountW
- RefSlice.Drop
- RefSlice.DropAt
- RefSlice.DropFirst
- RefSlice.DropFirstN
- RefSlice.DropLast
- RefSlice.DropLastN
- RefSlice.Each
- RefSlice.EachE
- RefSlice.EachI
- RefSlice.EachIE
- RefSlice.EachR
- RefSlice.EachRE
- RefSlice.EachRI
- RefSlice.EachRIE
- RefSlice.Empty
- RefSlice.First
- RefSlice.FirstN
- RefSlice.Index
- RefSlice.Insert
- RefSlice.Join
- RefSlice.Last
- RefSlice.LastN
- RefSlice.Less
- RefSlice.Pair
- RefSlice.Pop
- RefSlice.PopN
- RefSlice.Prepend
- RefSlice.RefSlice
- RefSlice.Reverse
- RefSlice.ReverseM
- RefSlice.Select
- RefSlice.Set
- RefSlice.SetE
- RefSlice.Shift
- RefSlice.ShiftN
- RefSlice.Single
- RefSlice.Slice
- RefSlice.Sort
- RefSlice.SortM
- RefSlice.SortReverse
- RefSlice.SortReverseM
- RefSlice.String
- RefSlice.Swap
- RefSlice.Take
- RefSlice.TakeAt
- RefSlice.TakeW
- RefSlice.Uniq
- RefSlice.UniqM
- Reference
- SetOnEmpty
- SetOnFalseB
- SetOnTrueB
- SliceOfMap.Any (Contains)
- SliceOfMap.Any (ContainsAny)
- SliceOfMap.Any (Empty)
- SliceOfMap.Any (NotEmpty)
- SliceOfMap.AnyS
- SliceOfMap.AppendV
- SliceOfMap.At
- SliceOfMap.Clear
- SliceOfMap.Concat
- SliceOfMap.ConcatM
- SliceOfMap.Copy
- SliceOfMap.Count
- SliceOfMap.CountW
- SliceOfMap.Drop
- SliceOfMap.DropAt
- SliceOfMap.DropFirst
- SliceOfMap.DropFirstN
- SliceOfMap.DropLast
- SliceOfMap.DropLastN
- SliceOfMap.DropW
- SliceOfMap.Each
- SliceOfMap.EachE
- SliceOfMap.EachI
- SliceOfMap.Empty
- Str.All (Contains)
- Str.AllS
- Str.Any (Contains)
- Str.Any (ContainsAny)
- Str.Any (Empty)
- Str.Any (NotEmpty)
- Str.AnyS
- Str.AnyW
- Str.Append
- Str.AppendV
- Str.Ascii
- Str.AsciiA
- Str.AsciiOnly
- Str.At
- Str.B
- Str.Clear
- Str.Concat
- Str.ConcatM
- Str.Contains
- Str.ContainsAny
- Str.ContainsRune
- Str.Copy
- Str.Count
- Str.CountW
- Str.Drop
- Str.DropAt
- Str.DropFirst
- Str.DropFirstN
- Str.DropLast
- Str.DropLastN
- Str.DropW
- Str.Each
- Str.EachE
- Str.EachI
- Str.EachIE
- Str.EachR
- Str.EachRE
- Str.EachRI
- Str.EachRIE
- Str.Empty
- Str.Fields
- Str.FieldsW
- Str.First
- Str.FirstN
- Str.G
- Str.HasAnyPrefix
- Str.HasAnyPrefixV
- Str.HasAnySuffix
- Str.HasAnySuffixV
- Str.HasPrefix
- Str.HasSuffix
- Str.Index
- Str.IndexAny
- Str.IndexChar
- Str.Insert
- Str.Join
- Str.Last
- Str.LastIndex
- Str.LastIndexAny
- Str.LastIndexChar
- Str.LastN
- Str.Len
- Str.Less
- Str.Map
- Str.Nil
- Str.O
- Str.Pair
- Str.Pop
- Str.PopN
- Str.Prepend
- Str.Replace
- Str.ReplaceAll
- Str.Reverse
- Str.ReverseM
- Str.Select
- Str.Set
- Str.SetE
- Str.Shift
- Str.ShiftN
- Str.Single
- Str.Slice
- Str.Sort
- Str.SortM
- Str.SortReverse
- Str.SortReverseM
- Str.Split
- Str.SplitAfter
- Str.SplitEscape
- Str.SplitQuotes
- Str.String
- Str.Swap
- Str.Take
- Str.TakeAt
- Str.TakeW
- Str.Title
- Str.ToLower
- Str.ToUpper
- Str.Trim
- Str.TrimFunc
- Str.TrimLeft
- Str.TrimLeftFunc
- Str.TrimPrefix
- Str.TrimRight
- Str.TrimRightFunc
- Str.TrimSuffix
- Str.Union
- Str.UnionM
- Str.Uniq
- Str.UniqM
- StringMap.Any
- StringMap.Clear
- StringMap.Copy
- StringMap.Delete
- StringMap.DeleteM
- StringMap.Dump
- StringMap.Exists
- StringMap.Generic
- StringMap.Get
- StringMap.Keys
- StringMap.Len
- StringMap.Merge
- StringMap.MergeG
- StringMap.O
- StringMap.Query
- StringMap.Remove
- StringMap.Set
- StringMap.SetM
- StringMap.Update
- StringSlice.All (Contains)
- StringSlice.All (ContainsAll)
- StringSlice.All (Empty)
- StringSlice.All (NotEmpty)
- StringSlice.AllS
- StringSlice.Any (Contains)
- StringSlice.Any (ContainsAny)
- StringSlice.Any (Empty)
- StringSlice.Any (NotEmpty)
- StringSlice.AnyS
- StringSlice.AnyW
- StringSlice.Append
- StringSlice.AppendV
- StringSlice.At
- StringSlice.Clear
- StringSlice.Concat
- StringSlice.ConcatM
- StringSlice.Copy
- StringSlice.Count
- StringSlice.CountW
- StringSlice.Drop
- StringSlice.DropAt
- StringSlice.DropFirst
- StringSlice.DropFirstN
- StringSlice.DropLast
- StringSlice.DropLastN
- StringSlice.DropW
- StringSlice.Each
- StringSlice.EachE
- StringSlice.EachI
- StringSlice.EachIE
- StringSlice.EachR
- StringSlice.EachRE
- StringSlice.EachRI
- StringSlice.EachRIE
- StringSlice.Empty
- StringSlice.First
- StringSlice.FirstN
- StringSlice.G
- StringSlice.Index
- StringSlice.Insert
- StringSlice.Join
- StringSlice.Last
- StringSlice.LastN
- StringSlice.Len
- StringSlice.Less
- StringSlice.Map
- StringSlice.Nil
- StringSlice.O
- StringSlice.Pair
- StringSlice.Pop
- StringSlice.PopN
- StringSlice.Prepend
- StringSlice.Reverse
- StringSlice.ReverseM
- StringSlice.Select
- StringSlice.Set
- StringSlice.SetE
- StringSlice.Shift
- StringSlice.ShiftN
- StringSlice.Single
- StringSlice.Slice
- StringSlice.Sort
- StringSlice.SortM
- StringSlice.SortReverse
- StringSlice.SortReverseM
- StringSlice.String
- StringSlice.Swap
- StringSlice.Take
- StringSlice.TakeAt
- StringSlice.TakeW
- StringSlice.Union
- StringSlice.UnionM
- StringSlice.Uniq
- StringSlice.UniqM
- ToBoolE
- ToChar
- ToFloat32
- ToFloat32E
- ToFloat64
- ToFloat64E
- ToInt
- ToIntE
- ToIntSliceE
- ToInterSlice
- ToSliceOfMapE
- ToStr
- ToString
- ToStringMapE
- ToStringSliceE
- ToStrsE
- ToTime
Constants ¶
This section is empty.
Variables ¶
var Break = errors.New("break")
Break is a brevity helper for breaking out of lambda loops
var ( // ReGraphicalOnly is a regex to filter on graphical runes only ReGraphicalOnly = regexp.MustCompile(`[^[:graph:]]+`) )
var TimeLayouts = []string{ time.RFC3339, time.RFC1123Z, time.RFC1123, time.RFC822Z, time.RFC822, time.RFC850, time.ANSIC, time.UnixDate, time.RubyDate, "January 2, 2006", "02 Jan 2006", "2006-01-02", time.Kitchen, time.StampNano, time.StampMicro, time.StampMilli, time.Stamp, }
TimeLayouts is just a simple wrapper around popular time layouts for time.Parse
Functions ¶
func DeReference ¶
func DeReference(obj interface{}) interface{}
DeReference dereferences the interface if needed returning a non-pointer type
Example ¶
DeReference --------------------------------------------------------------------------------------------------
slice := DeReference((*[]int)(nil)) fmt.Println(slice)
Output: []
func EitherStr ¶
EitherStr returns the first string if not empty else the second
Example ¶
fmt.Println(EitherStr("", "default"))
Output: default
func ExB ¶
ExB avoids Go's gastly 4 line monstrosity required to implement this providing instead a single clean line of code for lambdas.
func IdxFromSelector ¶
IdxFromSelector splits the given array index selector into individual components. The selector param is a jq like array selector [], []; size is the size of the target array. Getting a i==-1 and nil err indicates full array slice.
func MergeStringMap ¶
MergeStringMap b into a at location and returns the new modified a, b takes higher precedence and will override a. Only merges map types by key recursively, does not attempt to merge lists.
Example ¶
MergeStringMap --------------------------------------------------------------------------------------------------
fmt.Println(MergeStringMap(map[string]interface{}{"1": "two"}, map[string]interface{}{"1": "one"}))
Output: map[1:one]
func Reference ¶
func Reference(obj interface{}) interface{}
Reference converts the interface to a pointer type. Unlike DeReference nil may be returned as all pointers are simply passed through. This allows for custom default handling for callers.
Example ¶
Reference --------------------------------------------------------------------------------------------------
slice := Reference([]int{1, 2, 3}) fmt.Println(slice)
Output: &[1 2 3]
func SetOnEmpty ¶
SetOnEmpty updates the given result string to the given value if it is empty
Example ¶
result := "" fmt.Println(SetOnEmpty(&result, "foo"))
Output: foo
func SetOnFalseB ¶
SetOnFalseB only updates the result to the 'value' if the exp is false
Example ¶
result := false fmt.Println(SetOnFalseB(&result, true, false))
Output: true
func SetOnTrueA ¶
SetOnTrueA updates the given result string to the given value if the exp is true
func SetOnTrueB ¶
SetOnTrueB only updates the result to the 'value' if the exp is true
Example ¶
result := false fmt.Println(SetOnTrueB(&result, true, true))
Output: true
func ToBoolE ¶
ToBoolE converts an interface to a bool type.
Example ¶
ToBoolE --------------------------------------------------------------------------------------------------
fmt.Println(ToBoolE(1))
Output: true <nil>
func ToDuration ¶ added in v1.1.15
ToDuration converts an interface to a time.Duration type.
func ToDurationE ¶ added in v1.1.15
ToDurationE converts an interface to a time.Duration type.
func ToFloat32 ¶
func ToFloat32(obj interface{}) float32
ToFloat32 convert an interface to a float32 type.
Example ¶
ToFloat32 --------------------------------------------------------------------------------------------------
fmt.Println(ToFloat32("3.1"))
Output: 3.1
func ToFloat32E ¶
ToFloat32E convert an interface to a float32 type.
Example ¶
ToFloat32E --------------------------------------------------------------------------------------------------
fmt.Println(ToFloat32E("1.1"))
Output: 1.1 <nil>
func ToFloat64 ¶
func ToFloat64(obj interface{}) float64
ToFloat64 convert an interface to a float64 type.
Example ¶
ToFloat64 --------------------------------------------------------------------------------------------------
fmt.Println(ToFloat64("3.1"))
Output: 3.1
func ToFloat64E ¶
ToFloat64E convert an interface to a float64 type.
Example ¶
ToFloat64E --------------------------------------------------------------------------------------------------
fmt.Println(ToFloat64E("1.1"))
Output: 1.1 <nil>
func ToInt ¶
func ToInt(obj interface{}) int
ToInt convert an interface to an int type.
Example ¶
ToInt --------------------------------------------------------------------------------------------------
fmt.Println(ToInt("3"))
Output: 3
func ToInt16 ¶ added in v1.1.15
func ToInt16(obj interface{}) int16
ToInt16 convert an interface to an int16 type.
func ToInt32 ¶ added in v1.1.15
func ToInt32(obj interface{}) int32
ToInt32 convert an interface to an int32 type.
func ToInt64 ¶ added in v1.1.15
func ToInt64(obj interface{}) int64
ToInt64 convert an interface to an int64 type.
func ToInt8 ¶ added in v1.1.15
func ToInt8(obj interface{}) int8
ToInt8 convert an interface to an int8 type.
func ToIntE ¶
ToIntE convert an interface to an int type.
Example ¶
ToIntE --------------------------------------------------------------------------------------------------
fmt.Println(ToIntE("1"))
Output: 1 <nil>
func ToString ¶
func ToString(obj interface{}) string
ToString convert an interface to a string type.
Example ¶
ToString --------------------------------------------------------------------------------------------------
val := ToString(true) fmt.Println(val)
Output: true
func ToStringMapG ¶
func ToStringMapG(obj interface{}) map[string]interface{}
ToStringMapG converts an interface to a map[string]interface{} type
func ToStringMapGE ¶ added in v1.2.0
ToStringMapGE converts an interface to a map[string]interface{} type
func ToStrs ¶
func ToStrs(obj interface{}) (val []string)
ToStrs convert an interface to a []string type.
func ToStrsE ¶
ToStrsE convert an interface to a []string type.
Example ¶
ToStrsE --------------------------------------------------------------------------------------------------
fmt.Println(ToStrsE("1"))
Output: [1] <nil>
func ToTime ¶ added in v1.1.15
ToTime converts an interface to a time.Time type, invalid types will simply return the default time.Time
Example ¶
ToTime --------------------------------------------------------------------------------------------------
fmt.Println(ToTime("2008-01-10"))
Output: 2008-01-10 00:00:00 +0000 UTC
func ToUint ¶ added in v1.1.15
func ToUint(obj interface{}) uint
ToUint convert an interface to an uint type.
func ToUint16 ¶ added in v1.1.15
func ToUint16(obj interface{}) uint16
ToUint16 convert an interface to an uint16 type.
func ToUint32 ¶ added in v1.1.15
func ToUint32(obj interface{}) uint32
ToUint32 convert an interface to an uint32 type.
func ToUint64 ¶ added in v1.1.15
func ToUint64(obj interface{}) uint64
ToUint64 convert an interface to an uint64 type.
func ToUint8 ¶ added in v1.1.15
func ToUint8(obj interface{}) uint8
ToUint8 convert an interface to an uint8 type.
func UseLocalTime ¶ added in v1.1.42
func UseLocalTime(useLocal bool)
UseLocalTime controls whether the ToTime functions will use UTC or Local for Unix functions
func YAMLArray ¶ added in v1.2.0
func YAMLArray(obj interface{}) bool
YAMLArray checks if the given value is array compatible
Types ¶
type Char ¶
type Char rune
Char wraps the Go rune providing a way to distinguish it from an int32 where as a rune is indistinguishable from an int32. Provides convenience methods on par with rapid development languages.
func NewChar ¶
func NewChar(obj interface{}) *Char
NewChar creates a new chart from the given obj. Will always be non nil. Supports: string, *string, rune, *rune, byte, *byte
func NewCharV ¶
func NewCharV(obj ...interface{}) *Char
NewCharV creates a new chart from the given obj. Will always be non nil. Allows for empty Char with a Null value
func ToChar ¶
func ToChar(obj interface{}) *Char
ToChar convert an interface to a Char type.
Example ¶
ToChar --------------------------------------------------------------------------------------------------
val := ToChar("v") fmt.Println(val)
Output: v
func (*Char) Equal ¶
Equal returns true if the given *Char is value equal to this *Char.
Example ¶
Equal --------------------------------------------------------------------------------------------------
fmt.Println(NewChar('3').Equal('3'))
Output: true
func (*Char) Less ¶
Less returns true if the given *Char is less than this *Char.
Example ¶
Less --------------------------------------------------------------------------------------------------
fmt.Println(NewChar('3').Less('2'))
Output: false
type FloatMapBool ¶
FloatMapBool implements the Map interface providing a generic way to work with map types including convenience methods on par with rapid development languages.
func NewFloatMapBool ¶
func NewFloatMapBool(m ...map[float64]bool) *FloatMapBool
NewFloatMapBool creates a new empty FloatMapBool if nothing given else simply casts the given map to FloatMapBool.
func (*FloatMapBool) Any ¶
func (p *FloatMapBool) Any(keys ...interface{}) bool
Any tests if this Map is not empty or optionally if it contains any of the given variadic keys.
func (*FloatMapBool) Len ¶
func (p *FloatMapBool) Len() int
Len returns the number of elements in this Map.
func (*FloatMapBool) Set ¶
func (p *FloatMapBool) Set(key, val interface{}) bool
Set the value for the given key to the given val. Returns true if the key did not yet exists in this Map.
type FloatSlice ¶
type FloatSlice []float64
FloatSlice implements the Slice interface providing a generic way to work with slice types including convenience methods on par with rapid development languages.
func NewFloatSlice ¶
func NewFloatSlice(slice interface{}) *FloatSlice
NewFloatSlice creates a new *FloatSlice
Example ¶
slice := NewFloatSlice([]float64{1, 2, 3}) fmt.Println(slice)
Output: [1.000000 2.000000 3.000000]
func NewFloatSliceV ¶
func NewFloatSliceV(elems ...interface{}) *FloatSlice
NewFloatSliceV creates a new *FloatSlice from the given variadic elements. Always returns at least a reference to an empty FloatSlice.
Example (Empty) ¶
slice := NewFloatSliceV() fmt.Println(slice)
Output: []
Example (Variadic) ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice)
Output: [1.000000 2.000000 3.000000]
func ToFloatSlice ¶
func ToFloatSlice(obj interface{}) *FloatSlice
ToFloatSlice convert an interface to a FloatSlice type which will never be nil
func ToFloatSliceE ¶
func ToFloatSliceE(obj interface{}) (val *FloatSlice, err error)
ToFloatSliceE convert an interface to a FloatSlice type.
func (*FloatSlice) All ¶ added in v1.1.23
func (p *FloatSlice) All(elems ...interface{}) bool
All tests if this Slice is not empty or optionally if it contains all of the given variadic elements. Incompatible types will return false. Supports all possible int conversions
Example (Contains) ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.All(1))
Output: true
Example (ContainsAll) ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.All(2, 1))
Output: true
Example (Empty) ¶
All --------------------------------------------------------------------------------------------------
slice := NewFloatSliceV() fmt.Println(slice.All())
Output: false
Example (NotEmpty) ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.All())
Output: true
func (*FloatSlice) AllS ¶ added in v1.1.23
func (p *FloatSlice) AllS(slice interface{}) bool
AllS tests if this Slice contains all of the given Slice's elements. Incompatible types will return false. Supports FloatSlice, *FloatSlice, []float64 or *[]float64
Example ¶
AllS --------------------------------------------------------------------------------------------------
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.AllS([]float64{2, 1}))
Output: true
func (*FloatSlice) Any ¶
func (p *FloatSlice) Any(elems ...interface{}) bool
Any tests if this Slice is not empty or optionally if it contains any of the given variadic elements. Incompatible types will return false. Supports all possible int conversions
Example (Contains) ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Any(1))
Output: true
Example (ContainsAny) ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Any(0, 1))
Output: true
Example (Empty) ¶
slice := NewFloatSliceV() fmt.Println(slice.Any())
Output: false
Example (NotEmpty) ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Any())
Output: true
func (*FloatSlice) AnyS ¶
func (p *FloatSlice) AnyS(slice interface{}) bool
AnyS tests if this Slice contains any of the given Slice's elements. Incompatible types will return false. Supports FloatSlice, *FloatSlice, []float64 or *[]float64
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.AnyS([]float64{0, 1}))
Output: true
func (*FloatSlice) AnyW ¶
func (p *FloatSlice) AnyW(sel func(O) bool) bool
AnyW tests if this Slice contains any that match the lambda selector.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.AnyW(func(x O) bool { return ExB(x.(float64) == 2) }))
Output: true
func (*FloatSlice) Append ¶
func (p *FloatSlice) Append(elem interface{}) ISlice
Append an element to the end of this Slice and returns a reference to this Slice.
Example ¶
slice := NewFloatSliceV(1).Append(2).Append(3) fmt.Println(slice)
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) AppendV ¶
func (p *FloatSlice) AppendV(elems ...interface{}) ISlice
AppendV appends the variadic elements to the end of this Slice and returns a reference to this Slice.
Example ¶
slice := NewFloatSliceV(1).AppendV(2, 3) fmt.Println(slice)
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) At ¶
func (p *FloatSlice) At(i int) (elem *Object)
At returns the element at the given index location. Allows for negative notation.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.At(2))
Output: 3
func (*FloatSlice) Clear ¶
func (p *FloatSlice) Clear() ISlice
Clear modifies this Slice to clear out all elements and returns a reference to this Slice.
Example ¶
slice := NewFloatSliceV(1).Concat([]float64{2, 3}) fmt.Println(slice.Clear())
Output: []
func (*FloatSlice) Concat ¶
func (p *FloatSlice) Concat(slice interface{}) (new ISlice)
Concat returns a new Slice by appending the given Slice to this Slice using variadic expansion. Supports FloatSlice, *FloatSlice, []float64 or *[]float64
Example ¶
slice := NewFloatSliceV(1).Concat([]float64{2, 3}) fmt.Println(slice)
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) ConcatM ¶
func (p *FloatSlice) ConcatM(slice interface{}) ISlice
ConcatM modifies this Slice by appending the given Slice using variadic expansion and returns a reference to this ISlice. Supports FloatSlice, *FloatSlice, []float64 or *[]float64
Example ¶
slice := NewFloatSliceV(1).ConcatM([]float64{2, 3}) fmt.Println(slice)
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) Copy ¶
func (p *FloatSlice) Copy(indices ...int) (new ISlice)
Copy returns a new Slice with the indicated range of elements copied from this Slice. Expects nothing, in which case everything is copied, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Copy())
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) Count ¶
func (p *FloatSlice) Count(elem interface{}) (cnt int)
Count the number of elements in this Slice equal to the given element.
Example ¶
slice := NewFloatSliceV(1, 2, 2) fmt.Println(slice.Count(2.0))
Output: 2
func (*FloatSlice) CountW ¶
func (p *FloatSlice) CountW(sel func(O) bool) (cnt int)
CountW counts the number of elements in this Slice that match the lambda selector.
Example ¶
slice := NewFloatSliceV(1, 2, 2) fmt.Println(slice.CountW(func(x O) bool { return ExB(x.(float64) == 2) }))
Output: 2
func (*FloatSlice) Drop ¶
func (p *FloatSlice) Drop(indices ...int) ISlice
Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice. Expects nothing, in which case everything is dropped, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that DropAt(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Drop(0, 1))
Output: [3.000000]
func (*FloatSlice) DropAt ¶
func (p *FloatSlice) DropAt(i int) ISlice
DropAt modifies this Slice to delete the element at the given index location. Allows for negative notation. Returns a reference to this Slice.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.DropAt(1))
Output: [1.000000 3.000000]
func (*FloatSlice) DropFirst ¶
func (p *FloatSlice) DropFirst() ISlice
DropFirst modifies this Slice to delete the first element and returns a reference to this Slice.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.DropFirst())
Output: [2.000000 3.000000]
func (*FloatSlice) DropFirstN ¶
func (p *FloatSlice) DropFirstN(n int) ISlice
DropFirstN modifies this Slice to delete the first n elements and returns a reference to this Slice.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.DropFirstN(2))
Output: [3.000000]
func (*FloatSlice) DropLast ¶
func (p *FloatSlice) DropLast() ISlice
DropLast modifies this Slice to delete the last element and returns a reference to this Slice.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.DropLast())
Output: [1.000000 2.000000]
func (*FloatSlice) DropLastN ¶
func (p *FloatSlice) DropLastN(n int) ISlice
DropLastN modifies thi Slice to delete the last n elements and returns a reference to this Slice.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.DropLastN(2))
Output: [1.000000]
func (*FloatSlice) DropW ¶
func (p *FloatSlice) DropW(sel func(O) bool) ISlice
DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice. The slice is updated instantly when lambda expression is evaluated not after DropW completes.
func (*FloatSlice) Each ¶
func (p *FloatSlice) Each(action func(O)) ISlice
Each calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice
Example ¶
NewFloatSliceV(1, 2, 3).Each(func(x O) { fmt.Printf("%v", x) })
Output: 123
func (*FloatSlice) EachE ¶
func (p *FloatSlice) EachE(action func(O) error) (ISlice, error)
EachE calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewFloatSliceV(1, 2, 3).EachE(func(x O) error { fmt.Printf("%v", x) return nil })
Output: 123
func (*FloatSlice) EachI ¶
func (p *FloatSlice) EachI(action func(int, O)) ISlice
EachI calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice
Example ¶
NewFloatSliceV(1, 2, 3).EachI(func(i int, x O) { fmt.Printf("%v:%v", i, x) })
Output: 0:11:22:3
func (*FloatSlice) EachIE ¶
EachIE calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewFloatSliceV(1, 2, 3).EachIE(func(i int, x O) error { fmt.Printf("%v:%v", i, x) return nil })
Output: 0:11:22:3
func (*FloatSlice) EachR ¶
func (p *FloatSlice) EachR(action func(O)) ISlice
EachR calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice
Example ¶
NewFloatSliceV(1, 2, 3).EachR(func(x O) { fmt.Printf("%v", x) })
Output: 321
func (*FloatSlice) EachRE ¶
func (p *FloatSlice) EachRE(action func(O) error) (ISlice, error)
EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewFloatSliceV(1, 2, 3).EachRE(func(x O) error { fmt.Printf("%v", x) return nil })
Output: 321
func (*FloatSlice) EachRI ¶
func (p *FloatSlice) EachRI(action func(int, O)) ISlice
EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice
Example ¶
NewFloatSliceV(1, 2, 3).EachRI(func(i int, x O) { fmt.Printf("%v:%v", i, x) })
Output: 2:31:20:1
func (*FloatSlice) EachRIE ¶
EachRIE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewFloatSliceV(1, 2, 3).EachRIE(func(i int, x O) error { fmt.Printf("%v:%v", i, x) return nil })
Output: 2:31:20:1
func (*FloatSlice) Empty ¶
func (p *FloatSlice) Empty() bool
Empty tests if this Slice is empty.
Example ¶
Empty --------------------------------------------------------------------------------------------------
fmt.Println(NewFloatSliceV().Empty())
Output: true
func (*FloatSlice) First ¶
func (p *FloatSlice) First() (elem *Object)
First returns the first element in this Slice as Object. Object.Nil() == true will be returned when there are no elements in the slice.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.First())
Output: 1
func (*FloatSlice) FirstN ¶
func (p *FloatSlice) FirstN(n int) ISlice
FirstN returns the first n elements in this slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.
func (*FloatSlice) G ¶
func (p *FloatSlice) G() []float64
G returns the underlying data structure as a builtin Go type
Example ¶
G --------------------------------------------------------------------------------------------------
fmt.Println(NewFloatSliceV(1, 2, 3).G())
Output: [1 2 3]
func (*FloatSlice) Index ¶
func (p *FloatSlice) Index(elem interface{}) (loc int)
Index returns the index of the first element in this Slice where element == elem Returns a -1 if the element was not not found.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Index(2))
Output: 1
func (*FloatSlice) Insert ¶
func (p *FloatSlice) Insert(i int, obj interface{}) ISlice
Insert modifies this Slice to insert the given elements before the element(s) with the given index. Negative indices count backwards from the end of the slice, where -1 is the last element. If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice. If a Slice is given all elements will be inserted starting from the beging until the end. Slice is returned for chaining. Invalid index locations will not change the slice.
Example ¶
slice := NewFloatSliceV(1, 3) fmt.Println(slice.Insert(1, 2))
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) InterSlice ¶
func (p *FloatSlice) InterSlice() bool
InterSlice returns true if the underlying implementation is a RefSlice
func (*FloatSlice) Join ¶
func (p *FloatSlice) Join(separator ...string) (str *Object)
Join converts each element into a string then joins them together using the given separator or comma by default.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Join())
Output: 1,2,3
func (*FloatSlice) Last ¶
func (p *FloatSlice) Last() (elem *Object)
Last returns the last element in this Slice as an Object. Object.Nil() == true will be returned if there are no elements in the slice.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Last())
Output: 3
func (*FloatSlice) LastN ¶
func (p *FloatSlice) LastN(n int) ISlice
LastN returns the last n elements in this Slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.LastN(2))
Output: [2.000000 3.000000]
func (*FloatSlice) Len ¶
func (p *FloatSlice) Len() int
Len returns the number of elements in this Slice
Example ¶
Len --------------------------------------------------------------------------------------------------
fmt.Println(NewFloatSliceV(1, 2, 3).Len())
Output: 3
func (*FloatSlice) Less ¶
func (p *FloatSlice) Less(i, j int) bool
Less returns true if the element indexed by i is less than the element indexed by j.
Example ¶
slice := NewFloatSliceV(2, 3, 1) fmt.Println(slice.Less(0, 2))
Output: false
func (*FloatSlice) Map ¶
func (p *FloatSlice) Map(mod func(O) O) ISlice
Map creates a new slice with the modified elements from the lambda.
func (*FloatSlice) Nil ¶
func (p *FloatSlice) Nil() bool
Nil tests if this Slice is nil
Example ¶
Nil --------------------------------------------------------------------------------------------------
var slice *FloatSlice fmt.Println(slice.Nil())
Output: true
func (*FloatSlice) O ¶
func (p *FloatSlice) O() interface{}
O returns the underlying data structure as is
Example ¶
O --------------------------------------------------------------------------------------------------
fmt.Println(NewFloatSliceV(1, 2, 3))
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) Pair ¶
func (p *FloatSlice) Pair() (first, second *Object)
Pair simply returns the first and second Slice elements as Objects
Example ¶
slice := NewFloatSliceV(1, 2) first, second := slice.Pair() fmt.Println(first, second)
Output: 1 2
func (*FloatSlice) Pop ¶
func (p *FloatSlice) Pop() (elem *Object)
Pop modifies this Slice to remove the last element and returns the removed element as an Object.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Pop())
Output: 3
func (*FloatSlice) PopN ¶
func (p *FloatSlice) PopN(n int) (new ISlice)
PopN modifies this Slice to remove the last n elements and returns the removed elements as a new Slice.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.PopN(2))
Output: [2.000000 3.000000]
func (*FloatSlice) Prepend ¶
func (p *FloatSlice) Prepend(elem interface{}) ISlice
Prepend modifies this Slice to add the given element at the begining and returns a reference to this Slice.
Example ¶
slice := NewFloatSliceV(2, 3) fmt.Println(slice.Prepend(1))
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) RefSlice ¶
func (p *FloatSlice) RefSlice() bool
RefSlice returns true if the underlying implementation is a RefSlice
func (*FloatSlice) Reverse ¶
func (p *FloatSlice) Reverse() (new ISlice)
Reverse returns a new Slice with the order of the elements reversed.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Reverse())
Output: [3.000000 2.000000 1.000000]
func (*FloatSlice) ReverseM ¶
func (p *FloatSlice) ReverseM() ISlice
ReverseM modifies this Slice reversing the order of the elements and returns a reference to this Slice.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.ReverseM())
Output: [3.000000 2.000000 1.000000]
func (*FloatSlice) Select ¶
func (p *FloatSlice) Select(sel func(O) bool) (new ISlice)
Select creates a new slice with the elements that match the lambda selector.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Select(func(x O) bool { return ExB(x.(float64) == 2 || x.(float64) == 3) }))
Output: [2.000000 3.000000]
func (*FloatSlice) Set ¶
func (p *FloatSlice) Set(i int, elems interface{}) ISlice
Set the element(s) at the given index location to the given element(s). Allows for negative notation. Returns a reference to this Slice and swallows any errors.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Set(0, 0))
Output: [0.000000 2.000000 3.000000]
func (*FloatSlice) SetE ¶
func (p *FloatSlice) SetE(i int, elems interface{}) (ISlice, error)
SetE the element(s) at the given index location to the given element(s). Allows for negative notation. Returns a referenc to this Slice and an error if out of bounds or elem is the wrong type.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.SetE(0, 0))
Output: [0.000000 2.000000 3.000000] <nil>
func (*FloatSlice) Shift ¶
func (p *FloatSlice) Shift() (elem *Object)
Shift modifies this Slice to remove the first element and returns the removed element as an Object.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Shift())
Output: 1
func (*FloatSlice) ShiftN ¶
func (p *FloatSlice) ShiftN(n int) (new ISlice)
ShiftN modifies this Slice to remove the first n elements and returns the removed elements as a new Slice.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.ShiftN(2))
Output: [1.000000 2.000000]
func (*FloatSlice) Single ¶
func (p *FloatSlice) Single() bool
Single reports true if there is only one element in this Slice.
func (*FloatSlice) Slice ¶
func (p *FloatSlice) Slice(indices ...int) ISlice
Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation. Expects nothing, in which case everything is included, or two indices i and j, in which case an inclusive behavior is used such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.
e.g. NewFloatSliceV(1,2,3).Slice(0, -1) == [1,2,3] && NewFloatSliceV(1,2,3).Slice(1,2) == [2,3]
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Slice(1, -1))
Output: [2.000000 3.000000]
func (*FloatSlice) Sort ¶
func (p *FloatSlice) Sort() (new ISlice)
Sort returns a new Slice with sorted elements.
Example ¶
slice := NewFloatSliceV(2, 3, 1) fmt.Println(slice.Sort())
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) SortM ¶
func (p *FloatSlice) SortM() ISlice
SortM modifies this Slice sorting the elements and returns a reference to this Slice.
Example ¶
slice := NewFloatSliceV(2, 3, 1) fmt.Println(slice.SortM())
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) SortReverse ¶
func (p *FloatSlice) SortReverse() (new ISlice)
SortReverse returns a new Slice sorting the elements in reverse.
Example ¶
slice := NewFloatSliceV(2, 3, 1) fmt.Println(slice.SortReverse())
Output: [3.000000 2.000000 1.000000]
func (*FloatSlice) SortReverseM ¶
func (p *FloatSlice) SortReverseM() ISlice
SortReverseM modifies this Slice sorting the elements in reverse and returns a reference to this Slice.
Example ¶
slice := NewFloatSliceV(2, 3, 1) fmt.Println(slice.SortReverseM())
Output: [3.000000 2.000000 1.000000]
func (*FloatSlice) String ¶
func (p *FloatSlice) String() string
Returns a string representation of this Slice, implements the Stringer interface
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice)
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) Swap ¶
func (p *FloatSlice) Swap(i, j int)
Swap modifies this Slice swapping the indicated elements.
Example ¶
slice := NewFloatSliceV(2, 3, 1) slice.Swap(0, 2) slice.Swap(1, 2) fmt.Println(slice)
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) Take ¶
func (p *FloatSlice) Take(indices ...int) (new ISlice)
Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice. Expects nothing, in which case everything is taken, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Take(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.Take(0, 1))
Output: [1.000000 2.000000]
func (*FloatSlice) TakeAt ¶
func (p *FloatSlice) TakeAt(i int) (elem *Object)
TakeAt modifies this Slice removing the elemement at the given index location and returns the removed element as an Object. Allows for negative notation.
Example ¶
slice := NewFloatSliceV(1, 2, 3) fmt.Println(slice.TakeAt(1))
Output: 2
func (*FloatSlice) TakeW ¶
func (p *FloatSlice) TakeW(sel func(O) bool) (new ISlice)
TakeW modifies this Slice removing the elements that match the lambda selector and returns them as a new Slice.
func (*FloatSlice) ToIntSlice ¶
func (p *FloatSlice) ToIntSlice() (slice *IntSlice)
ToIntSlice converts the underlying slice into a *IntSlice
func (*FloatSlice) ToInterSlice ¶
func (p *FloatSlice) ToInterSlice() (slice []interface{})
ToInterSlice converts the given slice to a generic []interface{} slice
func (*FloatSlice) ToInts ¶
func (p *FloatSlice) ToInts() (slice []int)
ToInts converts the underlying slice into a []int
func (*FloatSlice) ToStringSlice ¶
func (p *FloatSlice) ToStringSlice() (slice *StringSlice)
ToStringSlice converts the underlying slice into a *StringSlice
func (*FloatSlice) ToStrs ¶
func (p *FloatSlice) ToStrs() (slice []string)
ToStrs converts the underlying slice into a []string slice
func (*FloatSlice) Union ¶
func (p *FloatSlice) Union(slice interface{}) (new ISlice)
Union returns a new Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports FloatSlice, *FloatSlice, []float64 or *[]float64
Example ¶
slice := NewFloatSliceV(1, 2) fmt.Println(slice.Union([]float64{2, 3}))
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) UnionM ¶
func (p *FloatSlice) UnionM(slice interface{}) ISlice
UnionM modifies this Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports FloatSlice, *FloatSlice, []float64 or *[]float64
Example ¶
slice := NewFloatSliceV(1, 2) fmt.Println(slice.UnionM([]float64{2, 3}))
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) Uniq ¶
func (p *FloatSlice) Uniq() (new ISlice)
Uniq returns a new Slice with all non uniq elements removed while preserving element order. Cost for this call vs the UniqM is roughly the same, this one is appending that one dropping.
Example ¶
slice := NewFloatSliceV(1, 2, 3, 3) fmt.Println(slice.Uniq())
Output: [1.000000 2.000000 3.000000]
func (*FloatSlice) UniqM ¶
func (p *FloatSlice) UniqM() ISlice
UniqM modifies this Slice to remove all non uniq elements while preserving element order. Cost for this call vs the Uniq is roughly the same, this one is dropping that one appending.
Example ¶
slice := NewFloatSliceV(1, 2, 3, 3) fmt.Println(slice.UniqM())
Output: [1.000000 2.000000 3.000000]
type IF ¶
type IF struct { State bool // Status of the result Error error // Errors that may have been captured Return []interface{} // Return values }
IF provides a way to deal with conditionals more elegantly in Go
func (*IF) Do ¶
Do executes the given function f with the given paramaters p if IF.State is true. When IF.State is true the IF object is Reset and the properties are used for the state of the current Do execution returning all return values from the function given to Do in the IF.Return slice and the first identified return bool will be used for IF.State and the first identified return error will be used for IF.Error.
type IMap ¶ added in v1.1.15
type IMap interface { Any(keys ...interface{}) bool // Any tests if this Map is not empty or optionally if it contains any of the given variadic keys. // AnyS(slice interface{}) bool // AnyS tests if this Map contains any of the given Slice's elements. // AnyW(sel func(O) bool) bool // AnyW tests if this Map contains any that match the lambda selector. // Append(elem interface{}) Slice // Append an element to the end of this Map and returns a reference to this Map. // AppendV(elems ...interface{}) Slice // AppendV appends the variadic elements to the end of this Map and returns a reference to this Map. Clear() IMap // Clear modifies this Map to clear out all key-value pairs and returns a reference to this Map. // Concat(slice interface{}) (new Slice) // Concat returns a new Slice by appending the given Slice to this Map using variadic expansion. // ConcatM(slice interface{}) Slice // ConcatM modifies this Map by appending the given Slice using variadic expansion and returns a reference to this Map. Copy(keys ...interface{}) (new IMap) // Copy returns a new Map with the indicated key-value pairs copied from this Map or all if not given. // Count(elem interface{}) (cnt int) // Count the number of elements in this Map equal to the given element. // CountW(sel func(O) bool) (cnt int) // CountW counts the number of elements in this Map that match the lambda selector. Delete(key interface{}) (val *Object) // Delete modifies this Map to delete the indicated key-value pair and returns the value from the Map. DeleteM(key interface{}) IMap // DeleteM modifies this Map to delete the indicated key-value pair and returns a reference to this Map rather than the key-value pair. //DeleteS(keys interface{}) (obj *Object) // DeleteS modifies this Map to delete the indicated key-value pairs and returns the values from the Map as a Slice. Exists(key interface{}) bool // Exists checks if the given key exists in this Map. // DeleteW(sel func(O) bool) Slice // DropW modifies this Map to delete the elements that match the lambda selector and returns a reference to this Map. // Each(action func(O)) Slice // Each calls the given lambda once for each element in this Map, passing in that element // EachE(action func(O) error) (ISlice, error) // EachE calls the given lambda once for each element in this Map, passing in that element // EachI(action func(int, O)) Slice // EachI calls the given lambda once for each element in this Map, passing in the index and element // EachIE(action func(int, O) error) (ISlice, error) // EachIE calls the given lambda once for each element in this Map, passing in the index and element // EachR(action func(O)) Slice // EachR calls the given lambda once for each element in this Map in reverse, passing in that element // EachRE(action func(O) error) (ISlice, error) // EachRE calls the given lambda once for each element in this Map in reverse, passing in that element // EachRI(action func(int, O)) Slice // EachRI calls the given lambda once for each element in this Map in reverse, passing in that element // EachRIE(action func(int, O) error) (ISlice, error) // EachRIE calls the given lambda once for each element in this Map in reverse, passing in that element // Empty() bool // Empty tests if this Map is empty. Generic() bool // Generic returns true if the underlying implementation uses reflection Get(key interface{}) (val *Object) // Get returns the value at the given key location. Returns empty *Object if not found. Update(selector string, val interface{}) IMap // Update sets the value for the given key location, using jq type selectors. Returns a reference to this Map. UpdateE(selector string, val interface{}) (m IMap, err error) // UpdateE sets the value for the given key location, using jq type selectors. Returns a reference to this Map. // Join(separator ...string) (str *Object) // Join converts each element into a string then joins them together using the given separator or comma by default. Keys() ISlice // Keys returns all the keys in this Map as a Slice of the key type. Len() int // Len returns the number of elements in this Map. M() (m *StringMap) // M is an alias to ToStringMap MG() (m map[string]interface{}) // MG is an alias to ToStringMapG Merge(m IMap, location ...string) IMap // Merge modifies this Map by overriding its values at location with the given map where they both exist and returns a reference to this Map. // Less(i, j int) bool // Less returns true if the element indexed by i is less than the element indexed by j. // Nil() bool // Nil tests if this Map is nil. O() interface{} // O returns the underlying data structure as is. // Pair() (first, second *Object) // Pair simply returns the first and second Slice elements as Objects. // Pop() (elem *Object) // Pop modifies this Map to remove the last element and returns the removed element as an Object. // PopN(n int) (new Map) // PopN modifies this Map to remove the last n elements and returns the removed elements as a new Map. // Prepend(elem interface{}) Slice // Prepend modifies this Map to add the given element at the begining and returns a reference to this Map. Query(selector string, params ...interface{}) (val *Object) // Query returns the value at the given selector location, using jq type selectors. Returns empty *Object if not found. QueryE(selector string, params ...interface{}) (val *Object, err error) // Query returns the value at the given selector location, using jq type selectors. Returns empty *Object if not found. Remove(selector string, params ...interface{}) IMap // Remove modifies this map to remove the value at the given selector location, using jq type selectors. Returns a reference to this Map RemoveE(selector string, params ...interface{}) (m IMap, err error) // RemoveE modifies this map to remove the value at the given selector location, using jq type selectors. Returns a reference to this Map // Reverse() (new Map) // Reverse returns a new Map with the order of the elements reversed. // ReverseM() Slice // ReverseM modifies this Map reversing the order of the elements and returns a reference to this Map. // Select(sel func(O) bool) (new Map) // Select creates a new Map with the elements that match the lambda selector. Set(selector, val interface{}) bool // Set the value for the given key to the given val. Returns true if the selector did not yet exists in this Map. SetM(selector, val interface{}) IMap // SetM the value for the given selector to the given val creating map if necessary. Returns a reference to this Map. // Shift() (elem *Object) // Shift modifies this Map to remove the first element and returns the removed element as an Object. // ShiftN(n int) (new Map) // ShiftN modifies this Map to remove the first n elements and returns the removed elements as a new Map. // Single() bool // Single reports true if there is only one element in this Map. // Slice(indices ...int) Slice // Slice returns a range of elements from this Map as a Slice reference to the original. Allows for negative notation. // Sort() (new Map) // Sort returns a new Map with sorted elements. // SortM() Slice // SortM modifies this Map sorting the elements and returns a reference to this Map. // SortReverse() (new Map) // SortReverse returns a new Map sorting the elements in reverse. // SortReverseM() Slice // SortReverseM modifies this Map sorting the elements in reverse and returns a reference to this Map. // String() string // Returns a string representation of this Map, implements the Stringer interface // Swap(i, j int) // Swap modifies this Map swapping the indicated elements. ToStringMap() (m *StringMap) // ToStringMap converts the map to a *StringMap ToStringMapG() (m map[string]interface{}) // ToStringMapG converts the map to a Golang map[string]interface{} // Take(indices ...int) (new Map) // Take modifies this Map removing the indicated range of elements from this Map and returning them as a new Map. // TakeAt(i int) (elem *Object) // TakeAt modifies this Map removing the elemement at the given index location and returns the removed element as an Object. // TakeW(sel func(O) bool) (new Map) // TakeW modifies this Map removing the elements that match the lambda selector and returns them as a new Map. // Union(slice interface{}) (new Map) // Union returns a new Map by joining uniq elements from this Map with uniq elements from the given Slice while preserving order. // UnionM(slice interface{}) Slice // UnionM modifies this Map by joining uniq elements from this Map with uniq elements from the given Slice while preserving order. // Uniq() (new Map) // Uniq returns a new Map with all non uniq elements removed while preserving element order. // UniqM() Slice // UniqM modifies this Map to remove all non uniq elements while preserving element order. YAML() (data string) // YAML converts the Map into a YAML string YAMLE() (data string, err error) // YAMLE converts the Map into a YAML string WriteJSON(filename string) (err error) // WriteJSON converts the Map into a map[string]interface{} then calls json.WriteJSON on it to write it out to disk. WriteYAML(filename string) (err error) // WriteYAML converts the Map into a map[string]interface{} then calls yaml.WriteYAML on it to write it out to disk. }
IMap provides a generic way to work with map types providing convenience methods on par with rapid development languages. 'this IMap' refers to the current map instance being operated on. 'new IMap' refers to a copy of the map.
type ISlice ¶
type ISlice interface { A() string // A is an alias to String for brevity All(elems ...interface{}) bool // All tests if this Slice is not empty or optionally if it contains all of the given variadic elements. AllS(slice interface{}) bool // AnyS tests if this Slice contains all of the given Slice's elements. Any(elems ...interface{}) bool // Any tests if this Slice is not empty or optionally if it contains any of the given variadic elements. AnyS(slice interface{}) bool // AnyS tests if this Slice contains any of the given Slice's elements. AnyW(sel func(O) bool) bool // AnyW tests if this Slice contains any that match the lambda selector. Append(elem interface{}) ISlice // Append an element to the end of this Slice and returns a reference to this Slice. AppendV(elems ...interface{}) ISlice // AppendV appends the variadic elements to the end of this Slice and returns a reference to this Slice. At(i int) (elem *Object) // At returns the element at the given index location. Allows for negative notation. Clear() ISlice // Clear modifies this Slice to clear out all elements and returns a reference to this Slice. Concat(slice interface{}) (new ISlice) // Concat returns a new Slice by appending the given Slice to this Slice using variadic expansion. ConcatM(slice interface{}) ISlice // ConcatM modifies this Slice by appending the given Slice using variadic expansion and returns a reference to this Slice. Copy(indices ...int) (new ISlice) // Copy returns a new Slice with the indicated range of elements copied from this Slice. Count(elem interface{}) (cnt int) // Count the number of elements in this Slice equal to the given element. CountW(sel func(O) bool) (cnt int) // CountW counts the number of elements in this Slice that match the lambda selector. Drop(indices ...int) ISlice // Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice. DropAt(i int) ISlice // DropAt modifies this Slice to delete the element at the given index location. Allows for negative notation. DropFirst() ISlice // DropFirst modifies this Slice to delete the first element and returns a reference to this Slice. DropFirstN(n int) ISlice // DropFirstN modifies this Slice to delete the first n elements and returns a reference to this Slice. DropLast() ISlice // DropLast modifies this Slice to delete the last element and returns a reference to this Slice. DropLastN(n int) ISlice // DropLastN modifies thi Slice to delete the last n elements and returns a reference to this Slice. DropW(sel func(O) bool) ISlice // DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice. Each(action func(O)) ISlice // Each calls the given lambda once for each element in this Slice, passing in that element EachE(action func(O) error) (ISlice, error) // EachE calls the given lambda once for each element in this Slice, passing in that element EachI(action func(int, O)) ISlice // EachI calls the given lambda once for each element in this Slice, passing in the index and element EachIE(action func(int, O) error) (ISlice, error) // EachIE calls the given lambda once for each element in this Slice, passing in the index and element EachR(action func(O)) ISlice // EachR calls the given lambda once for each element in this Slice in reverse, passing in that element EachRE(action func(O) error) (ISlice, error) // EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element EachRI(action func(int, O)) ISlice // EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element EachRIE(action func(int, O) error) (ISlice, error) // EachRIE calls the given lambda once for each element in this Slice in reverse, passing in that element Empty() bool // Empty tests if this Slice is empty. First() (elem *Object) // First returns the first element in this Slice as Object. FirstN(n int) ISlice // FirstN returns the first n elements in this slice as a Slice reference to the original. InterSlice() bool // Generic returns true if the underlying implementation uses reflection Index(elem interface{}) (loc int) // Index returns the index of the first element in this Slice where element == elem Insert(i int, elem interface{}) ISlice // Insert modifies this Slice to insert the given element(s) before the element with the given index. Join(separator ...string) (str *Object) // Join converts each element into a string then joins them together using the given separator or comma by default. Last() (elem *Object) // Last returns the last element in this Slice as an Object. LastN(n int) ISlice // LastN returns the last n elements in this Slice as a Slice reference to the original. Len() int // Len returns the number of elements in this Slice. Less(i, j int) bool // Less returns true if the element indexed by i is less than the element indexed by j. Nil() bool // Nil tests if this Slice is nil. Map(mod func(O) O) ISlice // Map creates a new slice with the modified elements from the lambda. O() interface{} // O returns the underlying data structure as is. Pair() (first, second *Object) // Pair simply returns the first and second Slice elements as Objects. Pop() (elem *Object) // Pop modifies this Slice to remove the last element and returns the removed element as an Object. PopN(n int) (new ISlice) // PopN modifies this Slice to remove the last n elements and returns the removed elements as a new Slice. Prepend(elem interface{}) ISlice // Prepend modifies this Slice to add the given element at the begining and returns a reference to this Slice. RefSlice() bool // RefSlice returns true if the underlying implementation is a RefSlice Reverse() (new ISlice) // Reverse returns a new Slice with the order of the elements reversed. ReverseM() ISlice // ReverseM modifies this Slice reversing the order of the elements and returns a reference to this Slice. S() (slice *StringSlice) // S is an alias to ToStringSlice Select(sel func(O) bool) (new ISlice) // Select creates a new slice with the elements that match the lambda selector. Set(i int, elems interface{}) ISlice // Set the element(s) at the given index location to the given element(s). Allows for negative notation. SetE(i int, elems interface{}) (ISlice, error) // SetE the element(s) at the given index location to the given element(s). Allows for negative notation. Shift() (elem *Object) // Shift modifies this Slice to remove the first element and returns the removed element as an Object. ShiftN(n int) (new ISlice) // ShiftN modifies this Slice to remove the first n elements and returns the removed elements as a new Slice. Single() bool // Single reports true if there is only one element in this Slice. Slice(indices ...int) ISlice // Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation. Sort() (new ISlice) // Sort returns a new Slice with sorted elements. SortM() ISlice // SortM modifies this Slice sorting the elements and returns a reference to this Slice. SortReverse() (new ISlice) // SortReverse returns a new Slice sorting the elements in reverse. SortReverseM() ISlice // SortReverseM modifies this Slice sorting the elements in reverse and returns a reference to this Slice. String() string // String returns a string representation of this Slice, implements the Stringer interface Swap(i, j int) // Swap modifies this Slice swapping the indicated elements. Take(indices ...int) (new ISlice) // Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice. TakeAt(i int) (elem *Object) // TakeAt modifies this Slice removing the elemement at the given index location and returns the removed element as an Object. TakeW(sel func(O) bool) (new ISlice) // TakeW modifies this Slice removing the elements that match the lambda selector and returns them as a new Slice. ToInts() (slice []int) // ToInts converts the given slice into a native []int type ToIntSlice() (slice *IntSlice) // ToIntSlice converts the given slice into a *IntSlice ToInterSlice() (slice []interface{}) // ToInterSlice converts the given slice to a generic []interface{} slice ToStrs() (slice []string) // ToStrs converts the underlying slice into a []string slice ToStringSlice() (slice *StringSlice) // ToStringSlice converts the underlying slice into a *StringSlice Union(slice interface{}) (new ISlice) // Union returns a new Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. UnionM(slice interface{}) ISlice // UnionM modifies this Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Uniq() (new ISlice) // Uniq returns a new Slice with all non uniq elements removed while preserving element order. UniqM() ISlice // UniqM modifies this Slice to remove all non uniq elements while preserving element order. }
ISlice provides a generic way to work with slice types providing convenience methods on par with rapid development languages. 'this Slice' refers to the current slice instance being operated on. 'new Slice' refers to a copy of the slice based on a new underlying Array.
func NewSliceV ¶
func NewSliceV(elems ...interface{}) (new ISlice)
NewSliceV creates a new Slice encapsulating the given variadic elements in a new Slice of that type using type assertion for optimized types. Non optimized types will fall back on reflection to generically handle the type incurring the full 10x reflection processing overhead. In the case where nothing is given a new *RefSlice will be returned.
Optimized: []int, []string, Str
func Slice ¶ added in v1.1.9
func Slice(obj interface{}) (new ISlice)
Slice provides a generic way to work with Slice types. It does this by wrapping Go types directly for optimized types thus avoiding reflection processing overhead and making a plethora of Slice methods available. Non optimized types will fall back on reflection to generically handle the type incurring the full 10x reflection processing overhead.
Optimized: []int, []string, StrSlice
type IntMapBool ¶
IntMapBool implements the Map interface providing a generic way to work with map types including convenience methods on par with rapid development languages.
func NewIntMapBool ¶
func NewIntMapBool(m ...map[int]bool) *IntMapBool
NewIntMapBool creates a new empty IntMapBool if nothing given else simply casts the given map to IntMapBool.
func (*IntMapBool) Any ¶
func (p *IntMapBool) Any(keys ...interface{}) bool
Any tests if this Map is not empty or optionally if it contains any of the given variadic keys.
func (*IntMapBool) Len ¶
func (p *IntMapBool) Len() int
Len returns the number of elements in this Map.
func (*IntMapBool) Set ¶
func (p *IntMapBool) Set(key, val interface{}) bool
Set the value for the given key to the given val. Returns true if the key did not yet exists in this Map.
type IntSlice ¶
type IntSlice []int
IntSlice implements the Slice interface providing a generic way to work with slice types including convenience methods on par with rapid development languages.
func NewIntSlice ¶
func NewIntSlice(slice interface{}) *IntSlice
NewIntSlice creates a new *IntSlice
Example ¶
slice := NewIntSlice([]int{1, 2, 3}) fmt.Println(slice)
Output: [1 2 3]
func NewIntSliceV ¶
func NewIntSliceV(elems ...interface{}) *IntSlice
NewIntSliceV creates a new *IntSlice from the given variadic elements. Always returns at least a reference to an empty IntSlice.
Example (Empty) ¶
slice := NewIntSliceV() fmt.Println(slice)
Output: []
Example (Variadic) ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice)
Output: [1 2 3]
func ToIntSlice ¶
func ToIntSlice(obj interface{}) *IntSlice
ToIntSlice convert an interface to a IntSlice type which will never be nil
func ToIntSliceE ¶
ToIntSliceE convert an interface to a IntSlice type.
Example ¶
ToIntSliceE --------------------------------------------------------------------------------------------------
fmt.Println(ToIntSliceE("1"))
Output: [1] <nil>
func (*IntSlice) All ¶ added in v1.1.23
All tests if this Slice is not empty or optionally if it contains all of the given variadic elements. Incompatible types will return false. Supports all possible int conversions
Example (Contains) ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.All(1))
Output: true
Example (ContainsAll) ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.All(2, 1))
Output: true
Example (Empty) ¶
All --------------------------------------------------------------------------------------------------
slice := NewIntSliceV() fmt.Println(slice.All())
Output: false
Example (NotEmpty) ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.All())
Output: true
func (*IntSlice) AllS ¶ added in v1.1.23
AllS tests if this Slice contains all of the given Slice's elements. Incompatible types will return false. Supports IntSlice, *IntSlice, []int or *[]int
Example ¶
AllS --------------------------------------------------------------------------------------------------
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.AllS([]int{2, 1}))
Output: true
func (*IntSlice) Any ¶
Any tests if this Slice is not empty or optionally if it contains any of the given variadic elements. Incompatible types will return false. Supports all possible int conversions
Example (Contains) ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Any(1))
Output: true
Example (ContainsAny) ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Any(0, 1))
Output: true
Example (Empty) ¶
slice := NewIntSliceV() fmt.Println(slice.Any())
Output: false
Example (NotEmpty) ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Any())
Output: true
func (*IntSlice) AnyS ¶
AnyS tests if this Slice contains any of the given Slice's elements. Incompatible types will return false. Supports IntSlice, *IntSlice, []int or *[]int
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.AnyS([]int{0, 1}))
Output: true
func (*IntSlice) AnyW ¶
AnyW tests if this Slice contains any that match the lambda selector.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.AnyW(func(x O) bool { return ExB(x.(int) == 2) }))
Output: true
func (*IntSlice) Append ¶
Append an element to the end of this Slice and returns a reference to this Slice.
Example ¶
slice := NewIntSliceV(1).Append(2).Append(3) fmt.Println(slice)
Output: [1 2 3]
func (*IntSlice) AppendV ¶
AppendV appends the variadic elements to the end of this Slice and returns a reference to this Slice.
Example ¶
slice := NewIntSliceV(1).AppendV(2, 3) fmt.Println(slice)
Output: [1 2 3]
func (*IntSlice) At ¶
At returns the element at the given index location. Allows for negative notation.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.At(2))
Output: 3
func (*IntSlice) Clear ¶
Clear modifies this Slice to clear out all elements and returns a reference to this Slice.
Example ¶
slice := NewIntSliceV(1).Concat([]int{2, 3}) fmt.Println(slice.Clear())
Output: []
func (*IntSlice) Concat ¶
Concat returns a new Slice by appending the given Slice to this Slice using variadic expansion. Supports IntSlice, *IntSlice, []int or *[]int
Example ¶
slice := NewIntSliceV(1).Concat([]int{2, 3}) fmt.Println(slice)
Output: [1 2 3]
func (*IntSlice) ConcatM ¶
ConcatM modifies this Slice by appending the given Slice using variadic expansion and returns a reference to this Slice. Supports IntSlice, *IntSlice, []int or *[]int
Example ¶
slice := NewIntSliceV(1).ConcatM([]int{2, 3}) fmt.Println(slice)
Output: [1 2 3]
func (*IntSlice) Copy ¶
Copy returns a new Slice with the indicated range of elements copied from this Slice. Expects nothing, in which case everything is copied, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Copy())
Output: [1 2 3]
func (*IntSlice) Count ¶
Count the number of elements in this Slice equal to the given element.
Example ¶
slice := NewIntSliceV(1, 2, 2) fmt.Println(slice.Count(2))
Output: 2
func (*IntSlice) CountW ¶
CountW counts the number of elements in this Slice that match the lambda selector.
Example ¶
slice := NewIntSliceV(1, 2, 2) fmt.Println(slice.CountW(func(x O) bool { return ExB(x.(int) == 2) }))
Output: 2
func (*IntSlice) Drop ¶
Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice. Expects nothing, in which case everything is dropped, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that DropAt(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Drop(0, 1))
Output: [3]
func (*IntSlice) DropAt ¶
DropAt modifies this Slice to delete the element at the given index location. Allows for negative notation. Returns a reference to this Slice.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.DropAt(1))
Output: [1 3]
func (*IntSlice) DropFirst ¶
DropFirst modifies this Slice to delete the first element and returns a reference to this Slice.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.DropFirst())
Output: [2 3]
func (*IntSlice) DropFirstN ¶
DropFirstN modifies this Slice to delete the first n elements and returns a reference to this Slice.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.DropFirstN(2))
Output: [3]
func (*IntSlice) DropLast ¶
DropLast modifies this Slice to delete the last element and returns a reference to this Slice.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.DropLast())
Output: [1 2]
func (*IntSlice) DropLastN ¶
DropLastN modifies thi Slice to delete the last n elements and returns a reference to this Slice.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.DropLastN(2))
Output: [1]
func (*IntSlice) DropW ¶
DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice. The slice is updated instantly when lambda expression is evaluated not after DropW completes.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.DropW(func(x O) bool { return ExB(x.(int)%2 == 0) }))
Output: [1 3]
func (*IntSlice) Each ¶
Each calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice
Example ¶
NewIntSliceV(1, 2, 3).Each(func(x O) { fmt.Printf("%v", x) })
Output: 123
func (*IntSlice) EachE ¶
EachE calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewIntSliceV(1, 2, 3).EachE(func(x O) error { fmt.Printf("%v", x) return nil })
Output: 123
func (*IntSlice) EachI ¶
EachI calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice
Example ¶
NewIntSliceV(1, 2, 3).EachI(func(i int, x O) { fmt.Printf("%v:%v", i, x) })
Output: 0:11:22:3
func (*IntSlice) EachIE ¶
EachIE calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewIntSliceV(1, 2, 3).EachIE(func(i int, x O) error { fmt.Printf("%v:%v", i, x) return nil })
Output: 0:11:22:3
func (*IntSlice) EachR ¶
EachR calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice
Example ¶
NewIntSliceV(1, 2, 3).EachR(func(x O) { fmt.Printf("%v", x) })
Output: 321
func (*IntSlice) EachRE ¶
EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewIntSliceV(1, 2, 3).EachRE(func(x O) error { fmt.Printf("%v", x) return nil })
Output: 321
func (*IntSlice) EachRI ¶
EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice
Example ¶
NewIntSliceV(1, 2, 3).EachRI(func(i int, x O) { fmt.Printf("%v:%v", i, x) })
Output: 2:31:20:1
func (*IntSlice) EachRIE ¶
EachRIE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewIntSliceV(1, 2, 3).EachRIE(func(i int, x O) error { fmt.Printf("%v:%v", i, x) return nil })
Output: 2:31:20:1
func (*IntSlice) Empty ¶
Empty tests if this Slice is empty.
Example ¶
Empty --------------------------------------------------------------------------------------------------
fmt.Println(NewIntSliceV().Empty())
Output: true
func (*IntSlice) First ¶
First returns the first element in this Slice as Object. Object.Nil() == true will be returned when there are no elements in the slice.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.First())
Output: 1
func (*IntSlice) FirstN ¶
FirstN returns the first n elements in this slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.FirstN(2))
Output: [1 2]
func (*IntSlice) G ¶
G returns the underlying data structure as a builtin Go type
Example ¶
G --------------------------------------------------------------------------------------------------
fmt.Println(NewIntSliceV(1, 2, 3).G())
Output: [1 2 3]
func (*IntSlice) Index ¶
Index returns the index of the first element in this Slice where element == elem Returns a -1 if the element was not not found.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Index(2))
Output: 1
func (*IntSlice) Insert ¶
Insert modifies this Slice to insert the given elements before the element(s) with the given index. Negative indices count backwards from the end of the slice, where -1 is the last element. If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice. If a Slice is given all elements will be inserted starting from the beging until the end. Slice is returned for chaining. Invalid index locations will not change the slice.
Example ¶
slice := NewIntSliceV(1, 3) fmt.Println(slice.Insert(1, 2))
Output: [1 2 3]
func (*IntSlice) InterSlice ¶
InterSlice returns true if the underlying implementation is a RefSlice
func (*IntSlice) Join ¶
Join converts each element into a string then joins them together using the given separator or comma by default.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Join())
Output: 1,2,3
func (*IntSlice) Last ¶
Last returns the last element in this Slice as an Object. Object.Nil() == true will be returned if there are no elements in the slice.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Last())
Output: 3
func (*IntSlice) LastN ¶
LastN returns the last n elements in this Slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.LastN(2))
Output: [2 3]
func (*IntSlice) Len ¶
Len returns the number of elements in this Slice
Example ¶
Len --------------------------------------------------------------------------------------------------
fmt.Println(NewIntSliceV(1, 2, 3).Len())
Output: 3
func (*IntSlice) Less ¶
Less returns true if the element indexed by i is less than the element indexed by j.
Example ¶
slice := NewIntSliceV(2, 3, 1) fmt.Println(slice.Less(0, 2))
Output: false
func (*IntSlice) Nil ¶
Nil tests if this Slice is nil
Example ¶
Nil --------------------------------------------------------------------------------------------------
var slice *IntSlice fmt.Println(slice.Nil())
Output: true
func (*IntSlice) O ¶
func (p *IntSlice) O() interface{}
O returns the underlying data structure as is
Example ¶
O --------------------------------------------------------------------------------------------------
fmt.Println(NewIntSliceV(1, 2, 3))
Output: [1 2 3]
func (*IntSlice) Pair ¶
Pair simply returns the first and second Slice elements as Objects
Example ¶
slice := NewIntSliceV(1, 2) first, second := slice.Pair() fmt.Println(first, second)
Output: 1 2
func (*IntSlice) Pop ¶
Pop modifies this Slice to remove the last element and returns the removed element as an Object.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Pop())
Output: 3
func (*IntSlice) PopN ¶
PopN modifies this Slice to remove the last n elements and returns the removed elements as a new Slice.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.PopN(2))
Output: [2 3]
func (*IntSlice) Prepend ¶
Prepend modifies this Slice to add the given element at the begining and returns a reference to this Slice.
Example ¶
slice := NewIntSliceV(2, 3) fmt.Println(slice.Prepend(1))
Output: [1 2 3]
func (*IntSlice) Reverse ¶
Reverse returns a new Slice with the order of the elements reversed.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Reverse())
Output: [3 2 1]
func (*IntSlice) ReverseM ¶
ReverseM modifies this Slice reversing the order of the elements and returns a reference to this Slice.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.ReverseM())
Output: [3 2 1]
func (*IntSlice) Select ¶
Select creates a new slice with the elements that match the lambda selector.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Select(func(x O) bool { return ExB(x.(int) == 2 || x.(int) == 3) }))
Output: [2 3]
func (*IntSlice) Set ¶
Set the element(s) at the given index location to the given element(s). Allows for negative notation. Returns a reference to this Slice and swallows any errors.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Set(0, 0))
Output: [0 2 3]
func (*IntSlice) SetE ¶
SetE the element(s) at the given index location to the given element(s). Allows for negative notation. Returns a referenc to this Slice and an error if out of bounds or elem is the wrong type.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.SetE(0, 0))
Output: [0 2 3] <nil>
func (*IntSlice) Shift ¶
Shift modifies this Slice to remove the first element and returns the removed element as an Object.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Shift())
Output: 1
func (*IntSlice) ShiftN ¶
ShiftN modifies this Slice to remove the first n elements and returns the removed elements as a new Slice.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.ShiftN(2))
Output: [1 2]
func (*IntSlice) Single ¶
Single reports true if there is only one element in this Slice.
Example ¶
slice := NewIntSliceV(1) fmt.Println(slice.Single())
Output: true
func (*IntSlice) Slice ¶
Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation. Expects nothing, in which case everything is included, or two indices i and j, in which case an inclusive behavior is used such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.
e.g. NewIntSliceV(1,2,3).Slice(0, -1) == [1,2,3] && NewIntSliceV(1,2,3).Slice(1,2) == [2,3]
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Slice(1, -1))
Output: [2 3]
func (*IntSlice) Sort ¶
Sort returns a new Slice with sorted elements.
Example ¶
slice := NewIntSliceV(2, 3, 1) fmt.Println(slice.Sort())
Output: [1 2 3]
func (*IntSlice) SortM ¶
SortM modifies this Slice sorting the elements and returns a reference to this Slice.
Example ¶
slice := NewIntSliceV(2, 3, 1) fmt.Println(slice.SortM())
Output: [1 2 3]
func (*IntSlice) SortReverse ¶
SortReverse returns a new Slice sorting the elements in reverse.
Example ¶
slice := NewIntSliceV(2, 3, 1) fmt.Println(slice.SortReverse())
Output: [3 2 1]
func (*IntSlice) SortReverseM ¶
SortReverseM modifies this Slice sorting the elements in reverse and returns a reference to this Slice.
Example ¶
slice := NewIntSliceV(2, 3, 1) fmt.Println(slice.SortReverseM())
Output: [3 2 1]
func (*IntSlice) String ¶
Returns a string representation of this Slice, implements the Stringer interface
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice)
Output: [1 2 3]
func (*IntSlice) Swap ¶
Swap modifies this Slice swapping the indicated elements.
Example ¶
slice := NewIntSliceV(2, 3, 1) slice.Swap(0, 2) slice.Swap(1, 2) fmt.Println(slice)
Output: [1 2 3]
func (*IntSlice) Take ¶
Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice. Expects nothing, in which case everything is taken, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Take(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.Take(0, 1))
Output: [1 2]
func (*IntSlice) TakeAt ¶
TakeAt modifies this Slice removing the elemement at the given index location and returns the removed element as an Object. Allows for negative notation.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.TakeAt(1))
Output: 2
func (*IntSlice) TakeW ¶
TakeW modifies this Slice removing the elements that match the lambda selector and returns them as a new Slice.
Example ¶
slice := NewIntSliceV(1, 2, 3) fmt.Println(slice.TakeW(func(x O) bool { return ExB(x.(int)%2 == 0) }))
Output: [2]
func (*IntSlice) ToIntSlice ¶
ToIntSlice converts the underlying slice into a *IntSlice
func (*IntSlice) ToInterSlice ¶
func (p *IntSlice) ToInterSlice() (slice []interface{})
ToInterSlice converts the given slice to a generic []interface{} slice
func (*IntSlice) ToStringSlice ¶
func (p *IntSlice) ToStringSlice() (slice *StringSlice)
ToStringSlice converts the underlying slice into a *StringSlice
func (*IntSlice) Union ¶
Union returns a new Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports IntSlice, *IntSlice, []int or *[]int
Example ¶
slice := NewIntSliceV(1, 2) fmt.Println(slice.Union([]int{2, 3}))
Output: [1 2 3]
func (*IntSlice) UnionM ¶
UnionM modifies this Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports IntSlice, *IntSlice, []int or *[]int
Example ¶
slice := NewIntSliceV(1, 2) fmt.Println(slice.UnionM([]int{2, 3}))
Output: [1 2 3]
func (*IntSlice) Uniq ¶
Uniq returns a new Slice with all non uniq elements removed while preserving element order. Cost for this call vs the UniqM is roughly the same, this one is appending that one dropping.
Example ¶
slice := NewIntSliceV(1, 2, 3, 3) fmt.Println(slice.Uniq())
Output: [1 2 3]
type InterSlice ¶
type InterSlice []interface{}
InterSlice implements the Slice interface providing a generic way to work with slice types including convenience methods on par with rapid development languages. This type incurs some reflection overhead characteristics but not all and differs in one important way from the RefSlice type. The given slice will be converted to a slice of types interface and left that way while RefSlice keeps the internal types typed as they were originally.
func NewInterSlice ¶
func NewInterSlice(slice interface{}) (new *InterSlice)
NewInterSlice uses reflection to encapsulate the given Go slice type inside a new *InterSlice. Expects a Go slice type to be provided and will create an empty *InterSlice if nothing valid is given.
Example ¶
NewInterSlice function --------------------------------------------------------------------------------------------------
slice := NewInterSlice([]int{1, 2, 3}).O() fmt.Println(slice)
Output: [1 2 3]
func NewInterSliceV ¶
func NewInterSliceV(elems ...interface{}) (new *InterSlice)
NewInterSliceV creates a new *InterSlice from the given variadic elements. Always returns at least a reference to an empty InterSlice.
Example (Empty) ¶
NewInterSliceV function --------------------------------------------------------------------------------------------------
slice := NewInterSliceV() fmt.Println(slice.O())
Output: []
Example (Variadic) ¶
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.O())
Output: [1 2 3]
func ToInterSlice ¶
func ToInterSlice(obj interface{}) (slice *InterSlice)
ToInterSlice converts the given slice to an *InterSlice
Example ¶
ToInterSlice --------------------------------------------------------------------------------------------------
fmt.Println(ToInterSlice("3").O())
Output: [3]
func ToSlice ¶
func ToSlice(obj interface{}) (slice *InterSlice)
ToSlice is an alias to ToInterSlice
func (*InterSlice) All ¶ added in v1.1.23
func (p *InterSlice) All(elems ...interface{}) bool
All tests if this Slice is not empty or optionally if it contains all of the given variadic elements. Incompatible types will return false.
Example (Contains) ¶
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.All(1))
Output: true
Example (ContainsAll) ¶
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.All(2, 1))
Output: true
Example (Empty) ¶
All --------------------------------------------------------------------------------------------------
slice := NewInterSliceV() fmt.Println(slice.All())
Output: false
Example (NotEmpty) ¶
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.All())
Output: true
func (*InterSlice) AllS ¶ added in v1.1.23
func (p *InterSlice) AllS(slice interface{}) bool
AllS tests if this Slice contains all of the given Slice's elements. Incompatible types will return false. Supports InterSlice, *InterSlice, Slice and Go slice types
Example ¶
AllS --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.AllS([]int{2, 1}))
Output: true
func (*InterSlice) Any ¶
func (p *InterSlice) Any(elems ...interface{}) bool
Any tests if this Slice is not empty or optionally if it contains any of the given variadic elements. Incompatible types will return false.
Example (Contains) ¶
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Any(1))
Output: true
Example (ContainsAny) ¶
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Any(0, 1))
Output: true
Example (Empty) ¶
Any --------------------------------------------------------------------------------------------------
slice := NewInterSliceV() fmt.Println(slice.Any())
Output: false
Example (NotEmpty) ¶
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Any())
Output: true
func (*InterSlice) AnyS ¶
func (p *InterSlice) AnyS(slice interface{}) bool
AnyS tests if this Slice contains any of the given Slice's elements. Incompatible types will return false. Supports InterSlice, *InterSlice, Slice and Go slice types
Example ¶
AnyS --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.AnyS([]int{0, 1}))
Output: true
func (*InterSlice) AnyW ¶
func (p *InterSlice) AnyW(sel func(O) bool) bool
AnyW tests if this Slice contains any that match the lambda selector.
Example ¶
AnyW --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.AnyW(func(x O) bool { return ExB(x.(int) == 2) }))
Output: true
func (*InterSlice) Append ¶
func (p *InterSlice) Append(elem interface{}) ISlice
Append an element to the end of this Slice and returns a reference to this Slice.
Example ¶
Append --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1).Append(2).Append(3) fmt.Println(slice.O())
Output: [1 2 3]
func (*InterSlice) AppendV ¶
func (p *InterSlice) AppendV(elems ...interface{}) ISlice
AppendV appends the variadic elements to the end of this Slice and returns a reference to this Slice.
Example ¶
AppendV --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1).AppendV(2, 3) fmt.Println(slice.O())
Output: [1 2 3]
func (*InterSlice) At ¶
func (p *InterSlice) At(i int) (elem *Object)
At returns the element at the given index location. Allows for negative notation.
Example ¶
At --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.At(2).O())
Output: 3
func (*InterSlice) Clear ¶
func (p *InterSlice) Clear() ISlice
Clear modifies this Slice to clear out all elements and returns a reference to this Slice.
Example ¶
Clear --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1).ConcatM([]int{2, 3}) fmt.Println(slice.Clear().O())
Output: []
func (*InterSlice) Concat ¶
func (p *InterSlice) Concat(slice interface{}) (new ISlice)
Concat returns a new Slice by appending the given Slice to this Slice using variadic expansion. Supports InterSlice, *InterSlice, []int or *[]int
Example ¶
Concat --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1).Concat([]int{2, 3}) fmt.Println(slice.O())
Output: [1 2 3]
func (*InterSlice) ConcatM ¶
func (p *InterSlice) ConcatM(slice interface{}) ISlice
ConcatM modifies this Slice by appending the given Slice using variadic expansion and returns a reference to this Slice. Supports InterSlice, *InterSlice, Slice and Go slice types
Example ¶
ConcatM --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1).ConcatM([]int{2, 3}) fmt.Println(slice.O())
Output: [1 2 3]
func (*InterSlice) Copy ¶
func (p *InterSlice) Copy(indices ...int) (new ISlice)
Copy returns a new Slice with the indicated range of elements copied from this Slice. Expects nothing, in which case everything is copied, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.
Example ¶
Copy --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Copy().O())
Output: [1 2 3]
func (*InterSlice) Count ¶
func (p *InterSlice) Count(elem interface{}) (cnt int)
Count the number of elements in this Slice equal to the given element.
Example ¶
Count --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 2) fmt.Println(slice.Count(2))
Output: 2
func (*InterSlice) CountW ¶
func (p *InterSlice) CountW(sel func(O) bool) (cnt int)
CountW counts the number of elements in this Slice that match the lambda selector.
Example ¶
CountW --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 2) fmt.Println(slice.CountW(func(x O) bool { return ExB(x.(int) == 2) }))
Output: 2
func (*InterSlice) Drop ¶
func (p *InterSlice) Drop(indices ...int) ISlice
Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice. Expects nothing, in which case everything is dropped, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that DropAt(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
Example ¶
Drop --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Drop(1, 1).O())
Output: [1 3]
func (*InterSlice) DropAt ¶
func (p *InterSlice) DropAt(i int) ISlice
DropAt modifies this Slice to delete the element at the given index location. Allows for negative notation. Returns a reference to this Slice.
Example ¶
DropAt --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.DropAt(1).O())
Output: [1 3]
func (*InterSlice) DropFirst ¶
func (p *InterSlice) DropFirst() ISlice
DropFirst modifies this Slice to delete the first element and returns a reference to this Slice.
Example ¶
DropFirst --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.DropFirst().O())
Output: [2 3]
func (*InterSlice) DropFirstN ¶
func (p *InterSlice) DropFirstN(n int) ISlice
DropFirstN modifies this Slice to delete the first n elements and returns a reference to this Slice.
Example ¶
DropFirstN --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.DropFirstN(2).O())
Output: [3]
func (*InterSlice) DropLast ¶
func (p *InterSlice) DropLast() ISlice
DropLast modifies this Slice to delete the last element and returns a reference to this Slice.
Example ¶
DropLast --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.DropLast().O())
Output: [1 2]
func (*InterSlice) DropLastN ¶
func (p *InterSlice) DropLastN(n int) ISlice
DropLastN modifies thi Slice to delete the last n elements and returns a reference to this Slice.
Example ¶
DropLastN --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.DropLastN(2).O())
Output: [1]
func (*InterSlice) DropW ¶
func (p *InterSlice) DropW(sel func(O) bool) ISlice
DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice. The slice is updated instantly when lambda expression is evaluated not after DropW completes.
Example ¶
DropW --------------------------------------------------------------------------------------------------
slice := NewInterSliceV("1", "2", "3") fmt.Println(slice.DropW(func(x O) bool { return ExB(Obj(x).ToInt()%2 == 0) }).O())
Output: [1 3]
func (*InterSlice) Each ¶
func (p *InterSlice) Each(action func(O)) ISlice
Each calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice
Example ¶
Each --------------------------------------------------------------------------------------------------
NewInterSliceV(1, 2, 3).Each(func(x O) { fmt.Printf("%v", x) })
Output: 123
func (*InterSlice) EachE ¶
func (p *InterSlice) EachE(action func(O) error) (ISlice, error)
EachE calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
EachE --------------------------------------------------------------------------------------------------
NewInterSliceV(1, 2, 3).EachE(func(x O) error { fmt.Printf("%v", x) return nil })
Output: 123
func (*InterSlice) EachI ¶
func (p *InterSlice) EachI(action func(int, O)) ISlice
EachI calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice
Example ¶
EachI --------------------------------------------------------------------------------------------------
NewInterSliceV(1, 2, 3).EachI(func(i int, x O) { fmt.Printf("%v:%v", i, x) })
Output: 0:11:22:3
func (*InterSlice) EachIE ¶
EachIE calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
EachIE --------------------------------------------------------------------------------------------------
NewInterSliceV(1, 2, 3).EachIE(func(i int, x O) error { fmt.Printf("%v:%v", i, x) return nil })
Output: 0:11:22:3
func (*InterSlice) EachR ¶
func (p *InterSlice) EachR(action func(O)) ISlice
EachR calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice
Example ¶
EachR --------------------------------------------------------------------------------------------------
NewInterSliceV(1, 2, 3).EachR(func(x O) { fmt.Printf("%v", x) })
Output: 321
func (*InterSlice) EachRE ¶
func (p *InterSlice) EachRE(action func(O) error) (ISlice, error)
EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
EachRE --------------------------------------------------------------------------------------------------
NewInterSliceV(1, 2, 3).EachRE(func(x O) error { fmt.Printf("%v", x) return nil })
Output: 321
func (*InterSlice) EachRI ¶
func (p *InterSlice) EachRI(action func(int, O)) ISlice
EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice
Example ¶
EachRI --------------------------------------------------------------------------------------------------
NewInterSliceV(1, 2, 3).EachRI(func(i int, x O) { fmt.Printf("%v:%v", i, x) })
Output: 2:31:20:1
func (*InterSlice) EachRIE ¶
EachRIE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
EachRIE --------------------------------------------------------------------------------------------------
NewInterSliceV(1, 2, 3).EachRIE(func(i int, x O) error { fmt.Printf("%v:%v", i, x) return nil })
Output: 2:31:20:1
func (*InterSlice) Empty ¶
func (p *InterSlice) Empty() bool
Empty tests if this Slice is empty.
Example ¶
Empty --------------------------------------------------------------------------------------------------
fmt.Println(NewInterSliceV().Empty())
Output: true
func (*InterSlice) First ¶
func (p *InterSlice) First() (elem *Object)
First returns the first element in this Slice as Object. Object.Nil() == true will be returned when there are no elements in the slice.
Example ¶
First --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.First().O())
Output: 1
func (*InterSlice) FirstN ¶
func (p *InterSlice) FirstN(n int) ISlice
FirstN returns the first n elements in this slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.
Example ¶
FirstN --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.FirstN(2).O())
Output: [1 2]
func (*InterSlice) G ¶
func (p *InterSlice) G() []interface{}
G returns the underlying Go type as is
func (*InterSlice) Index ¶
func (p *InterSlice) Index(elem interface{}) (loc int)
Index returns the index of the first element in this Slice where element == elem Returns a -1 if the element was not not found.
Example ¶
Index --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Index(2))
Output: 1
func (*InterSlice) Insert ¶
func (p *InterSlice) Insert(i int, obj interface{}) ISlice
Insert modifies this Slice to insert the given element before the element with the given index. Negative indices count backwards from the end of the slice, where -1 is the last element. If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice. If a Slice is given all elements will be inserted starting from the beging until the end. Slice is returned for chaining. Invalid index locations will not change the slice.
Example ¶
Insert --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 3) fmt.Println(slice.Insert(1, 2).O())
Output: [1 2 3]
func (*InterSlice) InterSlice ¶
func (p *InterSlice) InterSlice() bool
InterSlice returns true if the underlying implementation is a RefSlice
Example ¶
InterSlice --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.InterSlice())
Output: true
func (*InterSlice) Join ¶
func (p *InterSlice) Join(separator ...string) (str *Object)
Join converts each element into a string then joins them together using the given separator or comma by default.
Example ¶
Join --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Join())
Output: 1,2,3
func (*InterSlice) Last ¶
func (p *InterSlice) Last() (elem *Object)
Last returns the last element in this Slice as an Object. Object.Nil() == true will be returned if there are no elements in the slice.
Example ¶
Last --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Last())
Output: 3
func (*InterSlice) LastN ¶
func (p *InterSlice) LastN(n int) ISlice
LastN returns the last n elements in this Slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.
Example ¶
LastN --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.LastN(2).O())
Output: [2 3]
func (*InterSlice) Len ¶
func (p *InterSlice) Len() int
Len returns the number of elements in this Slice
func (*InterSlice) Less ¶
func (p *InterSlice) Less(i, j int) bool
Less returns true if the element indexed by i is less than the element indexed by j. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.
Example ¶
Less --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(2, 3, 1) fmt.Println(slice.Sort().O())
Output: [1 2 3]
func (*InterSlice) Map ¶
func (p *InterSlice) Map(mod func(O) O) ISlice
Map creates a new slice with the modified elements from the lambda.
Example ¶
Map --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Map(func(x O) O { return x.(int) + 1 }).O())
Output: [2 3 4]
func (*InterSlice) O ¶
func (p *InterSlice) O() interface{}
O returns the underlying data structure as is
func (*InterSlice) Pair ¶
func (p *InterSlice) Pair() (first, second *Object)
Pair simply returns the first and second Slice elements as Objects
Example ¶
slice := NewInterSliceV(1, 2) first, second := slice.Pair() fmt.Println(first.O(), second.O())
Output: 1 2
func (*InterSlice) Pop ¶
func (p *InterSlice) Pop() (elem *Object)
Pop modifies this Slice to remove the last element and returns the removed element as an Object.
Example ¶
Pop --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Pop())
Output: 3
func (*InterSlice) PopN ¶
func (p *InterSlice) PopN(n int) (new ISlice)
PopN modifies this Slice to remove the last n elements and returns the removed elements as a new Slice.
Example ¶
PopN --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.PopN(2))
Output: [2 3]
func (*InterSlice) Prepend ¶
func (p *InterSlice) Prepend(elem interface{}) ISlice
Prepend modifies this Slice to add the given element at the begining and returns a reference to this Slice.
Example ¶
Prepend --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(2, 3) fmt.Println(slice.Prepend(1).O())
Output: [1 2 3]
func (*InterSlice) RefSlice ¶
func (p *InterSlice) RefSlice() bool
RefSlice returns true if the underlying implementation is a RefSlice
func (*InterSlice) Reverse ¶
func (p *InterSlice) Reverse() (new ISlice)
Reverse returns a new Slice with the order of the elements reversed.
Example ¶
Reverse --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Reverse())
Output: [3 2 1]
func (*InterSlice) ReverseM ¶
func (p *InterSlice) ReverseM() ISlice
ReverseM modifies this Slice reversing the order of the elements and returns a reference to this Slice.
Example ¶
ReverseM --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.ReverseM())
Output: [3 2 1]
func (*InterSlice) Select ¶
func (p *InterSlice) Select(sel func(O) bool) (new ISlice)
Select creates a new slice with the elements that match the lambda selector.
Example ¶
Select --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Select(func(x O) bool { return ExB(x.(int) == 2 || x.(int) == 3) }))
Output: [2 3]
func (*InterSlice) Set ¶
func (p *InterSlice) Set(i int, elem interface{}) ISlice
Set the element at the given index location to the given element. Allows for negative notation. Returns a reference to this Slice and swallows any errors.
Example ¶
Set --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Set(0, 0).O())
Output: [0 2 3]
func (*InterSlice) SetE ¶
func (p *InterSlice) SetE(i int, elems interface{}) (ISlice, error)
SetE the element at the given index location to the given element. Allows for negative notation. Returns a referenc to this Slice and an error if out of bounds or elem is the wrong type.
Example ¶
SetE --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.SetE(0, 0))
Output: [0 2 3] <nil>
func (*InterSlice) Shift ¶
func (p *InterSlice) Shift() (elem *Object)
Shift modifies this Slice to remove the first element and returns the removed element as an Object.
Example ¶
Shift --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Shift().O())
Output: 1
func (*InterSlice) ShiftN ¶
func (p *InterSlice) ShiftN(n int) (new ISlice)
ShiftN modifies this Slice to remove the first n elements and returns the removed elements as a new Slice.
Example ¶
ShiftN --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.ShiftN(2).O())
Output: [1 2]
func (*InterSlice) Single ¶
func (p *InterSlice) Single() bool
Single reports true if there is only one element in this Slice.
Example ¶
slice := NewInterSliceV(1) fmt.Println(slice.Single())
Output: true
func (*InterSlice) Slice ¶
func (p *InterSlice) Slice(indices ...int) ISlice
Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation. Expects nothing, in which case everything is included, or two indices i and j, in which case an inclusive behavior is used such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.
e.g. NewInterSliceV(1,2,3).Slice(0, -1) == [1,2,3] && NewInterSliceV(1,2,3).Slice(1,2) == [2,3]
Example ¶
Slice --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Slice(1, -1).O())
Output: [2 3]
func (*InterSlice) Sort ¶
func (p *InterSlice) Sort() (new ISlice)
Sort returns a new Slice with sorted elements. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.
Example ¶
Sort --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(2, 3, 1) fmt.Println(slice.Sort())
Output: [1 2 3]
func (*InterSlice) SortM ¶
func (p *InterSlice) SortM() ISlice
SortM modifies this Slice sorting the elements and returns a reference to this Slice. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.
Example ¶
SortM --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(2, 3, 1) fmt.Println(slice.SortM())
Output: [1 2 3]
func (*InterSlice) SortReverse ¶
func (p *InterSlice) SortReverse() (new ISlice)
SortReverse returns a new Slice sorting the elements in reverse. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.
Example ¶
SortReverse --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(2, 3, 1) fmt.Println(slice.SortReverse())
Output: [3 2 1]
func (*InterSlice) SortReverseM ¶
func (p *InterSlice) SortReverseM() ISlice
SortReverseM modifies this Slice sorting the elements in reverse and returns a reference to this Slice. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.
Example ¶
SortReverseM --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(2, 3, 1) fmt.Println(slice.SortReverseM())
Output: [3 2 1]
func (*InterSlice) String ¶
func (p *InterSlice) String() string
Returns a string representation of this Slice, implements the Stringer interface
Example ¶
String --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice)
Output: [1 2 3]
func (*InterSlice) Swap ¶
func (p *InterSlice) Swap(i, j int)
Swap modifies this Slice swapping the indicated elements.
Example ¶
Swap --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(2, 3, 1) slice.Swap(0, 2) slice.Swap(1, 2) fmt.Println(slice.O())
Output: [1 2 3]
func (*InterSlice) Take ¶
func (p *InterSlice) Take(indices ...int) (new ISlice)
Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice. Expects nothing, in which case everything is taken, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Take(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
Example ¶
Take --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.Take(0, 1))
Output: [1 2]
func (*InterSlice) TakeAt ¶
func (p *InterSlice) TakeAt(i int) (elem *Object)
TakeAt modifies this Slice removing the elemement at the given index location and returns the removed element as an Object. Allows for negative notation.
Example ¶
TakeAt --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.TakeAt(2).O())
Output: 3
func (*InterSlice) TakeW ¶
func (p *InterSlice) TakeW(sel func(O) bool) (new ISlice)
TakeW modifies this Slice removing the elements that match the lambda selector and returns them as a new Slice.
Example ¶
TakeW --------------------------------------------------------------------------------------------------
slice := NewInterSliceV(1, 2, 3) fmt.Println(slice.TakeW(func(x O) bool { return ExB(x.(int)%2 == 0) }))
Output: [2]
func (*InterSlice) ToIntSlice ¶
func (p *InterSlice) ToIntSlice() (slice *IntSlice)
ToIntSlice converts the underlying slice into a *IntSlice
func (*InterSlice) ToInterSlice ¶
func (p *InterSlice) ToInterSlice() (slice []interface{})
ToInterSlice converts the given slice to a generic []interface{} slice
func (*InterSlice) ToInts ¶
func (p *InterSlice) ToInts() (slice []int)
ToInts converts the underlying slice into a []int
func (*InterSlice) ToStringSlice ¶
func (p *InterSlice) ToStringSlice() (slice *StringSlice)
ToStringSlice converts the underlying slice into a *StringSlice
func (*InterSlice) ToStrs ¶
func (p *InterSlice) ToStrs() (slice []string)
ToStrs converts the underlying slice into a []string slice
func (*InterSlice) Union ¶
func (p *InterSlice) Union(slice interface{}) (new ISlice)
Union returns a new Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports InterSlice, *InterSlice, Slice and Go slice types
func (*InterSlice) UnionM ¶
func (p *InterSlice) UnionM(slice interface{}) ISlice
UnionM modifies this Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports InterSlice, *InterSlice, Slice and Go slice types
func (*InterSlice) Uniq ¶
func (p *InterSlice) Uniq() (new ISlice)
Uniq returns a new Slice with all non uniq elements removed while preserving element order. Cost for this call vs the UniqM is roughly the same, this one is appending that one dropping.
func (*InterSlice) UniqM ¶
func (p *InterSlice) UniqM() ISlice
UniqM modifies this Slice to remove all non uniq elements while preserving element order. Cost for this call vs the Uniq is roughly the same, this one is dropping that one appending.
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object is a wrapper around an interface{} value providing a number of export methods for casting and converting to other types via the excellent cast package.
func Obj ¶
func Obj(obj interface{}) *Object
Obj creates a new Object from the given obj appending the Object methods
func (*Object) String ¶
String returns a string representation of the Object, implements Stringer interface.
func (*Object) ToDuration ¶
ToDuration converts an interface to a time.Duration type.
func (*Object) ToDurationE ¶
ToDurationE converts an interface to a time.Duration type.
func (*Object) ToFloat32E ¶
ToFloat32E converts an interface to a float32 type.
func (*Object) ToFloat64E ¶
ToFloat64E converts an interface to a float64 type.
func (*Object) ToIntSlice ¶
ToIntSlice converts an interface to a *IntSlice type.
func (*Object) ToIntSliceE ¶
ToIntSliceE converts an interface to a *IntSlice type.
func (*Object) ToIntSliceG ¶
ToIntSliceG converts an interface to a []int type.
func (*Object) ToIntSliceGE ¶
ToIntSliceGE converts an interface to a []int type.
func (*Object) ToSliceOfMap ¶ added in v1.2.1
func (p *Object) ToSliceOfMap() *SliceOfMap
ToSliceOfMap converts an interface to a *SliceOfMap type.
func (*Object) ToSliceOfMapE ¶ added in v1.2.1
func (p *Object) ToSliceOfMapE() (*SliceOfMap, error)
ToSliceOfMapE converts an interface to a *SliceOfMap type.
func (*Object) ToSliceOfMapG ¶ added in v1.2.1
ToSliceOfMapG converts an interface to a []map[string]interface{} type.
func (*Object) ToSliceOfMapGE ¶ added in v1.2.1
ToSliceOfMapGE converts an interface to a []map[string]interface{} type.
func (*Object) ToStringMap ¶
ToStringMap converts an interface to a *StringMap type.
func (*Object) ToStringMapE ¶
ToStringMapE converts an interface to a *StringMap type.
func (*Object) ToStringMapG ¶
ToStringMapG converts an interface to a map[string]interface{} type.
func (*Object) ToStringMapGE ¶
ToStringMapGE converts an interface to a map[string]interface{} type.
func (*Object) ToStringSlice ¶
func (p *Object) ToStringSlice() *StringSlice
ToStringSlice converts an interface to a *StringSlice type.
func (*Object) ToStringSliceE ¶
func (p *Object) ToStringSliceE() (*StringSlice, error)
ToStringSliceE converts an interface to a *StringSlice type.
type RefSlice ¶
type RefSlice struct {
// contains filtered or unexported fields
}
RefSlice implements the Slice interface providing a generic way to work with slice types including convenience methods on par with rapid development languages. This type incurs the typical 10x reflection overhead costs. For high performance use the Slice implementation matching the type your working with or implement a new type that satisfies the Slice interface.
func NewRefSlice ¶
func NewRefSlice(slice interface{}) (new *RefSlice)
NewRefSlice uses reflection to encapsulate the given Go slice type inside a new *RefSlice. Expects a Go slice type to be provided and will create an empty *RefSlice if nothing valid is given.
Example ¶
NewRefSlice function --------------------------------------------------------------------------------------------------
slice := NewRefSlice([]int{1, 2, 3}) fmt.Println(slice)
Output: [1 2 3]
func NewRefSliceV ¶
func NewRefSliceV(elems ...interface{}) (new *RefSlice)
NewRefSliceV creates a new *RefSlice from the given variadic elements. Always returns at least a reference to an empty RefSlice.
Example (Empty) ¶
NewRefSliceV function --------------------------------------------------------------------------------------------------
slice := NewRefSliceV() fmt.Println(slice.O())
Output: <nil>
Example (Variadic) ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.O())
Output: [1 2 3]
func (*RefSlice) All ¶ added in v1.1.23
All tests if this Slice is not empty or optionally if it contains all of the given variadic elements; Incompatible types will return false.
func (*RefSlice) AllS ¶ added in v1.1.23
AllS tests if this Slice contains all of the given Slice's elements; Incompatible types will return false; Supports RefSlice, *RefSlice, Slice and Go slice types
func (*RefSlice) Any ¶
Any tests if this Slice is not empty or optionally if it contains any of the given variadic elements. Incompatible types will return false.
Example (Contains) ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Any(1))
Output: true
Example (ContainsAny) ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Any(0, 1))
Output: true
Example (Empty) ¶
slice := NewRefSliceV() fmt.Println(slice.Any())
Output: false
Example (NotEmpty) ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Any())
Output: true
func (*RefSlice) AnyS ¶
AnyS tests if this Slice contains any of the given Slice's elements. Incompatible types will return false. Supports RefSlice, *RefSlice, Slice and Go slice types
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.AnyS([]int{0, 1}))
Output: true
func (*RefSlice) AnyW ¶
AnyW tests if this Slice contains any that match the lambda selector.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.AnyW(func(x O) bool { return ExB(x.(int) == 2) }))
Output: true
func (*RefSlice) Append ¶
Append an element to the end of this Slice and returns a reference to this Slice.
Example ¶
slice := NewRefSliceV(1).Append(2).Append(3) fmt.Println(slice.O())
Output: [1 2 3]
func (*RefSlice) AppendV ¶
AppendV appends the variadic elements to the end of this Slice and returns a reference to this Slice.
Example ¶
slice := NewRefSliceV(1).AppendV(2, 3) fmt.Println(slice.O())
Output: [1 2 3]
func (*RefSlice) At ¶
At returns the element at the given index location. Allows for negative notation.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.At(2).O())
Output: 3
func (*RefSlice) Clear ¶
Clear modifies this Slice to clear out all elements and returns a reference to this Slice.
Example ¶
slice := NewRefSliceV(1).ConcatM([]int{2, 3}) fmt.Println(slice.Clear().O())
Output: []
func (*RefSlice) Concat ¶
Concat returns a new Slice by appending the given Slice to this Slice using variadic expansion. Supports RefSlice, *RefSlice, []int or *[]int
Example ¶
slice := NewRefSliceV(1).Concat([]int{2, 3}) fmt.Println(slice.O())
Output: [1 2 3]
func (*RefSlice) ConcatM ¶
ConcatM modifies this Slice by appending the given Slice using variadic expansion and returns a reference to this Slice. Supports RefSlice, *RefSlice, Slice and Go slice types
Example ¶
slice := NewRefSliceV(1).ConcatM([]int{2, 3}) fmt.Println(slice.O())
Output: [1 2 3]
func (*RefSlice) Copy ¶
Copy returns a new Slice with the indicated range of elements copied from this Slice. Expects nothing, in which case everything is copied, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Copy().O())
Output: [1 2 3]
func (*RefSlice) Count ¶
Count the number of elements in this Slice equal to the given element.
Example ¶
slice := NewRefSliceV(1, 2, 2) fmt.Println(slice.Count(2))
Output: 2
func (*RefSlice) CountW ¶
CountW counts the number of elements in this Slice that match the lambda selector.
Example ¶
slice := NewRefSliceV(1, 2, 2) fmt.Println(slice.CountW(func(x O) bool { return ExB(x.(int) == 2) }))
Output: 2
func (*RefSlice) Drop ¶
Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice. Expects nothing, in which case everything is dropped, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that DropAt(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Drop(1, 1).O())
Output: [1 3]
func (*RefSlice) DropAt ¶
DropAt modifies this Slice to delete the element at the given index location. Allows for negative notation. Returns a reference to this Slice.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.DropAt(1))
Output: [1 3]
func (*RefSlice) DropFirst ¶
DropFirst modifies this Slice to delete the first element and returns a reference to this Slice.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.DropFirst().O())
Output: [2 3]
func (*RefSlice) DropFirstN ¶
DropFirstN modifies this Slice to delete the first n elements and returns a reference to this Slice.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.DropFirstN(2).O())
Output: [3]
func (*RefSlice) DropLast ¶
DropLast modifies this Slice to delete the last element and returns a reference to this Slice.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.DropLast().O())
Output: [1 2]
func (*RefSlice) DropLastN ¶
DropLastN modifies thi Slice to delete the last n elements and returns a reference to this Slice.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.DropLastN(2).O())
Output: [1]
func (*RefSlice) DropW ¶
DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice. The slice is updated instantly when lambda expression is evaluated not after DropW completes.
func (*RefSlice) Each ¶
Each calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice
Example ¶
NewRefSliceV(1, 2, 3).Each(func(x O) { fmt.Printf("%v", x) })
Output: 123
func (*RefSlice) EachE ¶
EachE calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewRefSliceV(1, 2, 3).EachE(func(x O) error { fmt.Printf("%v", x) return nil })
Output: 123
func (*RefSlice) EachI ¶
EachI calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice
Example ¶
NewRefSliceV(1, 2, 3).EachI(func(i int, x O) { fmt.Printf("%v:%v", i, x) })
Output: 0:11:22:3
func (*RefSlice) EachIE ¶
EachIE calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewRefSliceV(1, 2, 3).EachIE(func(i int, x O) error { fmt.Printf("%v:%v", i, x) return nil })
Output: 0:11:22:3
func (*RefSlice) EachR ¶
EachR calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice
Example ¶
NewRefSliceV(1, 2, 3).EachR(func(x O) { fmt.Printf("%v", x) })
Output: 321
func (*RefSlice) EachRE ¶
EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewRefSliceV(1, 2, 3).EachRE(func(x O) error { fmt.Printf("%v", x) return nil })
Output: 321
func (*RefSlice) EachRI ¶
EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice
Example ¶
NewRefSliceV(1, 2, 3).EachRI(func(i int, x O) { fmt.Printf("%v:%v", i, x) })
Output: 2:31:20:1
func (*RefSlice) EachRIE ¶
EachRIE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewRefSliceV(1, 2, 3).EachRIE(func(i int, x O) error { fmt.Printf("%v:%v", i, x) return nil })
Output: 2:31:20:1
func (*RefSlice) Empty ¶
Empty tests if this Slice is empty.
Example ¶
Empty --------------------------------------------------------------------------------------------------
fmt.Println(NewRefSliceV().Empty())
Output: true
func (*RefSlice) First ¶
First returns the first element in this Slice as Object. Object.Nil() == true will be returned when there are no elements in the slice.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.First().O())
Output: 1
func (*RefSlice) FirstN ¶
FirstN returns the first n elements in this slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.FirstN(2).O())
Output: [1 2]
func (*RefSlice) Index ¶
Index returns the index of the first element in this Slice where element == elem Returns a -1 if the element was not not found.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Index(2))
Output: 1
func (*RefSlice) Insert ¶
Insert modifies this Slice to insert the given element before the element with the given index. Negative indices count backwards from the end of the slice, where -1 is the last element. If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice. If a Slice is given all elements will be inserted starting from the beging until the end. Slice is returned for chaining. Invalid index locations will not change the slice.
Example ¶
slice := NewRefSliceV(1, 3) fmt.Println(slice.Insert(1, 2).O())
Output: [1 2 3]
func (*RefSlice) InsertS ¶
InsertS modifies this Slice to insert the given elements before the element with the given index. Negative indices count backwards from the end of the slice, where -1 is the last element. If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice. If a Slice is given all elements will be inserted starting from the beging until the end. Slice is returned for chaining. Invalid index locations will not change the slice.
func (*RefSlice) InterSlice ¶
InterSlice returns true if the underlying implementation is a RefSlice
func (*RefSlice) Join ¶
Join converts each element into a string then joins them together using the given separator or comma by default.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Join())
Output: 1,2,3
func (*RefSlice) Last ¶
Last returns the last element in this Slice as an Object. Object.Nil() == true will be returned if there are no elements in the slice.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Last())
Output: 3
func (*RefSlice) LastN ¶
LastN returns the last n elements in this Slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.LastN(2).O())
Output: [2 3]
func (*RefSlice) Less ¶
Less returns true if the element indexed by i is less than the element indexed by j. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.
Example ¶
slice := NewRefSliceV(2, 3, 1) fmt.Println(slice.Sort().O())
Output: [1 2 3]
func (*RefSlice) O ¶
func (p *RefSlice) O() interface{}
O returns the underlying data structure as is
func (*RefSlice) Pair ¶
Pair simply returns the first and second Slice elements as Objects
Example ¶
slice := NewRefSliceV(1, 2) first, second := slice.Pair() fmt.Println(first.O(), second.O())
Output: 1 2
func (*RefSlice) Pop ¶
Pop modifies this Slice to remove the last element and returns the removed element as an Object.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Pop())
Output: 3
func (*RefSlice) PopN ¶
PopN modifies this Slice to remove the last n elements and returns the removed elements as a new Slice.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.PopN(2))
Output: [2 3]
func (*RefSlice) Prepend ¶
Prepend modifies this Slice to add the given element at the begining and returns a reference to this Slice.
Example ¶
slice := NewRefSliceV(2, 3) fmt.Println(slice.Prepend(1).O())
Output: [1 2 3]
func (*RefSlice) RefSlice ¶
RefSlice returns true if the underlying implementation is a RefSlice
Example ¶
RefSlicej --------------------------------------------------------------------------------------------------
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.RefSlice())
Output: true
func (*RefSlice) Reverse ¶
Reverse returns a new Slice with the order of the elements reversed.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Reverse())
Output: [3 2 1]
func (*RefSlice) ReverseM ¶
ReverseM modifies this Slice reversing the order of the elements and returns a reference to this Slice.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.ReverseM())
Output: [3 2 1]
func (*RefSlice) Select ¶
Select creates a new slice with the elements that match the lambda selector.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Select(func(x O) bool { return ExB(x.(int) == 2 || x.(int) == 3) }))
Output: [2 3]
func (*RefSlice) Set ¶
Set the element at the given index location to the given element. Allows for negative notation. Returns a reference to this Slice and swallows any errors.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Set(0, 0).O())
Output: [0 2 3]
func (*RefSlice) SetE ¶
SetE the element at the given index location to the given element. Allows for negative notation. Returns a referenc to this Slice and an error if out of bounds or elem is the wrong type.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.SetE(0, 0))
Output: [0 2 3] <nil>
func (*RefSlice) Shift ¶
Shift modifies this Slice to remove the first element and returns the removed element as an Object.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Shift().O())
Output: 1
func (*RefSlice) ShiftN ¶
ShiftN modifies this Slice to remove the first n elements and returns the removed elements as a new Slice.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.ShiftN(2).O())
Output: [1 2]
func (*RefSlice) Single ¶
Single reports true if there is only one element in this Slice.
Example ¶
slice := NewRefSliceV(1) fmt.Println(slice.Single())
Output: true
func (*RefSlice) Slice ¶
Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation. Expects nothing, in which case everything is included, or two indices i and j, in which case an inclusive behavior is used such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.
e.g. NewRefSliceV(1,2,3).Slice(0, -1) == [1,2,3] && NewRefSliceV(1,2,3).Slice(1,2) == [2,3]
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Slice(1, -1).O())
Output: [2 3]
func (*RefSlice) Sort ¶
Sort returns a new Slice with sorted elements. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.
Example ¶
slice := NewRefSliceV(2, 3, 1) fmt.Println(slice.Sort())
Output: [1 2 3]
func (*RefSlice) SortM ¶
SortM modifies this Slice sorting the elements and returns a reference to this Slice. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.
Example ¶
slice := NewRefSliceV(2, 3, 1) fmt.Println(slice.SortM())
Output: [1 2 3]
func (*RefSlice) SortReverse ¶
SortReverse returns a new Slice sorting the elements in reverse. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.
Example ¶
slice := NewRefSliceV(2, 3, 1) fmt.Println(slice.SortReverse())
Output: [3 2 1]
func (*RefSlice) SortReverseM ¶
SortReverseM modifies this Slice sorting the elements in reverse and returns a reference to this Slice. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.
Example ¶
slice := NewRefSliceV(2, 3, 1) fmt.Println(slice.SortReverseM())
Output: [3 2 1]
func (*RefSlice) String ¶
Returns a string representation of this Slice, implements the Stringer interface
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice)
Output: [1 2 3]
func (*RefSlice) Swap ¶
Swap modifies this Slice swapping the indicated elements.
Example ¶
slice := NewRefSliceV(2, 3, 1) slice.Swap(0, 2) slice.Swap(1, 2) fmt.Println(slice.O())
Output: [1 2 3]
func (*RefSlice) Take ¶
Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice. Expects nothing, in which case everything is taken, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Take(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.Take(0, 1))
Output: [1 2]
func (*RefSlice) TakeAt ¶
TakeAt modifies this Slice removing the elemement at the given index location and returns the removed element as an Object. Allows for negative notation.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.TakeAt(2).O())
Output: 3
func (*RefSlice) TakeW ¶
TakeW modifies this Slice removing the elements that match the lambda selector and returns them as a new Slice.
Example ¶
slice := NewRefSliceV(1, 2, 3) fmt.Println(slice.TakeW(func(x O) bool { return ExB(x.(int)%2 == 0) }))
Output: [2]
func (*RefSlice) ToIntSlice ¶
ToIntSlice converts the underlying slice into a *IntSlice
func (*RefSlice) ToInterSlice ¶
func (p *RefSlice) ToInterSlice() (slice []interface{})
ToInterSlice converts the given slice to a generic []interface{} slice
func (*RefSlice) ToStringSlice ¶
func (p *RefSlice) ToStringSlice() (slice *StringSlice)
ToStringSlice converts the underlying slice into a *StringSlice
func (*RefSlice) Union ¶
Union returns a new Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports RefSlice, *RefSlice, Slice and Go slice types
func (*RefSlice) UnionM ¶
UnionM modifies this Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports RefSlice, *RefSlice, Slice and Go slice types
func (*RefSlice) Uniq ¶
Uniq returns a new Slice with all non uniq elements removed while preserving element order. Cost for this call vs the UniqM is roughly the same, this one is appending that one dropping.
Example ¶
slice := NewRefSliceV(1, 2, 3, 3) fmt.Println(slice.Uniq())
Output: [1 2 3]
type RuneMapBool ¶
RuneMapBool implements the Map interface providing a generic way to work with map types including convenience methods on par with rapid development languages.
func NewRuneMapBool ¶
func NewRuneMapBool(m ...map[rune]bool) *RuneMapBool
NewRuneMapBool creates a new empty RuneMapBool if nothing given else simply casts the given map to RuneMapBool.
func (*RuneMapBool) Any ¶
func (p *RuneMapBool) Any(keys ...interface{}) bool
Any tests if this Map is not empty or optionally if it contains any of the given variadic keys.
func (*RuneMapBool) Len ¶
func (p *RuneMapBool) Len() int
Len returns the number of elements in this Map.
func (*RuneMapBool) Set ¶
func (p *RuneMapBool) Set(key, val interface{}) bool
Set the value for the given key to the given val. Returns true if the key did not yet exists in this Map.
type SliceOfMap ¶ added in v1.2.1
type SliceOfMap []*StringMap
SliceOfMap implements the Slice interface providing a generic way to work with slice types including convenience methods on par with rapid development languages.
func NewSliceOfMap ¶ added in v1.2.1
func NewSliceOfMap(slice interface{}) *SliceOfMap
NewSliceOfMap creates a new *SliceOfMap
Example ¶
slice := NewSliceOfMap([]map[string]interface{}{{"foo": "bar"}}) fmt.Println(slice)
Output: [&[{foo bar}]]
func NewSliceOfMapV ¶ added in v1.2.1
func NewSliceOfMapV(obj ...interface{}) *SliceOfMap
NewSliceOfMapV creates a new *SliceOfMap from the given variadic elements. Always returns at least a reference to an empty SliceOfMap.
Example (Empty) ¶
slice := NewSliceOfMapV() fmt.Println(slice)
Output: []
Example (Variadic) ¶
slice := NewSliceOfMapV(map[string]interface{}{"foo1": "1"}, map[string]interface{}{"foo2": "2"}) fmt.Println(slice)
Output: [&[{foo1 1}] &[{foo2 2}]]
func ToSliceOfMap ¶ added in v1.2.1
func ToSliceOfMap(obj interface{}) *SliceOfMap
ToSliceOfMap converts an interface to a SliceOfMap type.
func ToSliceOfMapE ¶ added in v1.2.1
func ToSliceOfMapE(obj interface{}) (val *SliceOfMap, err error)
ToSliceOfMapE converts an interface to a SliceOfMap type.
Example ¶
ToSliceOfMapE --------------------------------------------------------------------------------------------------
fmt.Println(ToSliceOfMapE([]map[interface{}]interface{}{{"1": "one"}}))
Output: [&[{1 one}]] <nil>
func (*SliceOfMap) A ¶ added in v1.2.1
func (p *SliceOfMap) A() string
A is an alias to String for brevity
func (*SliceOfMap) All ¶ added in v1.2.1
func (p *SliceOfMap) All(elems ...interface{}) bool
All tests if this Slice is not empty or optionally if it contains all of the given variadic elements. Incompatible types will return false.
func (*SliceOfMap) AllS ¶ added in v1.2.1
func (p *SliceOfMap) AllS(slice interface{}) bool
AllS tests if this Slice contains all of the given Slice's elements; Incompatible types will return false; Supports SliceOfMap, *SliceOfMap, []string or *[]string
func (*SliceOfMap) Any ¶ added in v1.2.1
func (p *SliceOfMap) Any(elems ...interface{}) bool
Any tests if this Slice is not empty or optionally if it contains any of the given variadic elements. Incompatible types will return false.
Example (Contains) ¶
slice := NewSliceOfMapV("1:", "2:", "3:") fmt.Println(slice.Any("1"))
Output: true
Example (ContainsAny) ¶
slice := NewSliceOfMapV("1:", "2:", "3:") fmt.Println(slice.Any("0", "1"))
Output: true
Example (Empty) ¶
slice := NewSliceOfMapV() fmt.Println(slice.Any())
Output: false
Example (NotEmpty) ¶
slice := NewSliceOfMapV("1:", "2:", "3:") fmt.Println(slice.Any())
Output: true
func (*SliceOfMap) AnyS ¶ added in v1.2.1
func (p *SliceOfMap) AnyS(slice interface{}) bool
AnyS tests if this Slice contains any of the given Slice's elements. Incompatible types will return false. Supports SliceOfMap, *SliceOfMap, []string or *[]string
Example ¶
slice := NewSliceOfMapV("1:", "2:", "3:") fmt.Println(slice.AnyS([]string{"0", "1"}))
Output: true
func (*SliceOfMap) AnyW ¶ added in v1.2.1
func (p *SliceOfMap) AnyW(sel func(O) bool) bool
AnyW tests if this Slice contains any that match the lambda selector.
func (*SliceOfMap) Append ¶ added in v1.2.1
func (p *SliceOfMap) Append(elem interface{}) ISlice
Append an element to the end of this Slice and returns a reference to this Slice.
func (*SliceOfMap) AppendV ¶ added in v1.2.1
func (p *SliceOfMap) AppendV(elems ...interface{}) ISlice
AppendV appends the variadic elements to the end of this Slice and returns a reference to this Slice.
Example ¶
slice := NewSliceOfMapV("1:").AppendV("2:", "3:") fmt.Println(slice)
Output: [&[{1 <nil>}] &[{2 <nil>}] &[{3 <nil>}]]
func (*SliceOfMap) At ¶ added in v1.2.1
func (p *SliceOfMap) At(i int) (elem *Object)
At returns the element at the given index location. Allows for negative notation.
Example ¶
slice := NewSliceOfMapV("1:", "2:", "3:") fmt.Println(slice.At(2))
Output: &[{3 <nil>}]
func (*SliceOfMap) Clear ¶ added in v1.2.1
func (p *SliceOfMap) Clear() ISlice
Clear modifies this Slice to clear out all elements and returns a reference to this Slice.
Example ¶
Clear --------------------------------------------------------------------------------------------------
slice := NewSliceOfMapV("1:").Concat([]string{"2", "3"}) fmt.Println(slice.Clear())
Output: []
func (*SliceOfMap) Concat ¶ added in v1.2.1
func (p *SliceOfMap) Concat(slice interface{}) (new ISlice)
Concat returns a new Slice by appending the given Slice to this Slice using variadic expansion. Supports SliceOfMap, *SliceOfMap, []string or *[]string
Example ¶
slice := NewSliceOfMapV("1:").Concat([]interface{}{"2:", "3:"}) fmt.Println(slice)
Output: [&[{1 <nil>}] &[{2 <nil>}] &[{3 <nil>}]]
func (*SliceOfMap) ConcatM ¶ added in v1.2.1
func (p *SliceOfMap) ConcatM(slice interface{}) ISlice
ConcatM modifies this Slice by appending the given Slice using variadic expansion and returns a reference to this Slice. Supports SliceOfMap, *SliceOfMap, []string or *[]string
Example ¶
slice := NewSliceOfMapV("1:").ConcatM([]interface{}{"2:", "3:"}) fmt.Println(slice)
Output: [&[{1 <nil>}] &[{2 <nil>}] &[{3 <nil>}]]
func (*SliceOfMap) Copy ¶ added in v1.2.1
func (p *SliceOfMap) Copy(indices ...int) (new ISlice)
Copy returns a new Slice with the indicated range of elements copied from this Slice. Expects nothing, in which case everything is copied, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.
Example ¶
slice := NewSliceOfMapV("1:", "2:", "3:") fmt.Println(slice.Copy())
Output: [&[{1 <nil>}] &[{2 <nil>}] &[{3 <nil>}]]
func (*SliceOfMap) Count ¶ added in v1.2.1
func (p *SliceOfMap) Count(key interface{}) (cnt int)
Count the number of elements in this Slice that contain the given key
Example ¶
slice := NewSliceOfMapV("1:", "2:", "2:") fmt.Println(slice.Count("2"))
Output: 2
func (*SliceOfMap) CountW ¶ added in v1.2.1
func (p *SliceOfMap) CountW(sel func(O) bool) (cnt int)
CountW counts the number of elements in this Slice that match the lambda selector.
Example ¶
slice := NewSliceOfMapV("1:", "2:", "2:") fmt.Println(slice.CountW(func(x O) bool { return ToStringMap(x).Exists("2") }))
Output: 2
func (*SliceOfMap) Drop ¶ added in v1.2.1
func (p *SliceOfMap) Drop(indices ...int) ISlice
Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice. Expects nothing, in which case everything is dropped, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that DropAt(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
Example ¶
slice := NewSliceOfMapV("1:", "2:", "3:") fmt.Println(slice.Drop(0, 1))
Output: [&[{3 <nil>}]]
func (*SliceOfMap) DropAt ¶ added in v1.2.1
func (p *SliceOfMap) DropAt(i int) ISlice
DropAt modifies this Slice to delete the element at the given index location. Allows for negative notation. Returns a reference to this Slice.
Example ¶
slice := NewSliceOfMapV("1:", "2:", "3:") fmt.Println(slice.DropAt(1))
Output: [&[{1 <nil>}] &[{3 <nil>}]]
func (*SliceOfMap) DropFirst ¶ added in v1.2.1
func (p *SliceOfMap) DropFirst() ISlice
DropFirst modifies this Slice to delete the first element and returns a reference to this Slice.
Example ¶
slice := NewSliceOfMapV("1:", "2:", "3:") fmt.Println(slice.DropFirst())
Output: [&[{2 <nil>}] &[{3 <nil>}]]
func (*SliceOfMap) DropFirstN ¶ added in v1.2.1
func (p *SliceOfMap) DropFirstN(n int) ISlice
DropFirstN modifies this Slice to delete the first n elements and returns a reference to this Slice.
Example ¶
slice := NewSliceOfMapV("1:", "2:", "3:") fmt.Println(slice.DropFirstN(2))
Output: [&[{3 <nil>}]]
func (*SliceOfMap) DropLast ¶ added in v1.2.1
func (p *SliceOfMap) DropLast() ISlice
DropLast modifies this Slice to delete the last element and returns a reference to this Slice.
Example ¶
slice := NewSliceOfMapV("1:", "2:", "3:") fmt.Println(slice.DropLast())
Output: [&[{1 <nil>}] &[{2 <nil>}]]
func (*SliceOfMap) DropLastN ¶ added in v1.2.1
func (p *SliceOfMap) DropLastN(n int) ISlice
DropLastN modifies thi Slice to delete the last n elements and returns a reference to this Slice.
Example ¶
slice := NewSliceOfMapV("1:", "2:", "3:") fmt.Println(slice.DropLastN(2))
Output: [&[{1 <nil>}]]
func (*SliceOfMap) DropW ¶ added in v1.2.1
func (p *SliceOfMap) DropW(sel func(O) bool) ISlice
DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice. The slice is updated instantly when lambda expression is evaluated not after DropW completes.
Example ¶
slice := NewSliceOfMapV("1:", "2:", "3:") fmt.Println(slice.DropW(func(x O) bool { return ToStringMap(x).Exists("2") }))
Output: [&[{1 <nil>}] &[{3 <nil>}]]
func (*SliceOfMap) Each ¶ added in v1.2.1
func (p *SliceOfMap) Each(action func(O)) ISlice
Each calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice
Example ¶
NewSliceOfMapV([]map[string]interface{}{{"foo": "bar"}}).Each(func(x O) { fmt.Printf("%v", x) })
Output: &[{foo bar}]
func (*SliceOfMap) EachE ¶ added in v1.2.1
func (p *SliceOfMap) EachE(action func(O) error) (ISlice, error)
EachE calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewSliceOfMapV([]map[string]interface{}{{"foo": "bar"}}).EachE(func(x O) error { fmt.Printf("%v", x) return nil })
Output: &[{foo bar}]
func (*SliceOfMap) EachI ¶ added in v1.2.1
func (p *SliceOfMap) EachI(action func(int, O)) ISlice
EachI calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice
Example ¶
NewSliceOfMapV("1:", "2:", "3:").EachI(func(i int, x O) { fmt.Printf("%v %v", i, x) })
Output: 0 &[{1 <nil>}]1 &[{2 <nil>}]2 &[{3 <nil>}]
func (*SliceOfMap) EachIE ¶ added in v1.2.1
EachIE calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice and any error from the lambda.
func (*SliceOfMap) EachR ¶ added in v1.2.1
func (p *SliceOfMap) EachR(action func(O)) ISlice
EachR calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice
func (*SliceOfMap) EachRE ¶ added in v1.2.1
func (p *SliceOfMap) EachRE(action func(O) error) (ISlice, error)
EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
func (*SliceOfMap) EachRI ¶ added in v1.2.1
func (p *SliceOfMap) EachRI(action func(int, O)) ISlice
EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice
func (*SliceOfMap) EachRIE ¶ added in v1.2.1
EachRIE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.
func (*SliceOfMap) Empty ¶ added in v1.2.1
func (p *SliceOfMap) Empty() bool
Empty tests if this Slice is empty.
Example ¶
Empty --------------------------------------------------------------------------------------------------
fmt.Println(NewSliceOfMapV().Empty())
Output: true
func (*SliceOfMap) First ¶ added in v1.2.1
func (p *SliceOfMap) First() (elem *Object)
First returns the first element in this Slice as Object. Object.Nil() == true will be returned when there are no elements in the slice.
func (*SliceOfMap) FirstN ¶ added in v1.2.1
func (p *SliceOfMap) FirstN(n int) ISlice
FirstN returns the first n elements in this slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.
func (*SliceOfMap) G ¶ added in v1.2.1
func (p *SliceOfMap) G() []map[string]interface{}
G returns the underlying data structure as a builtin Go type
func (*SliceOfMap) Index ¶ added in v1.2.1
func (p *SliceOfMap) Index(elem interface{}) (loc int)
Index returns the index of the first element in this Slice where element == elem Returns a -1 if the element was not not found.
func (*SliceOfMap) Insert ¶ added in v1.2.1
func (p *SliceOfMap) Insert(i int, obj interface{}) ISlice
Insert modifies this Slice to insert the given elements before the element(s) with the given index. Negative indices count backwards from the end of the slice, where -1 is the last element. If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice. If a Slice is given all elements will be inserted starting from the beging until the end. Slice is returned for chaining. Invalid index locations will not change the slice.
func (*SliceOfMap) InterSlice ¶ added in v1.2.1
func (p *SliceOfMap) InterSlice() bool
InterSlice returns true if the underlying implementation is a RefSlice
func (*SliceOfMap) Join ¶ added in v1.2.1
func (p *SliceOfMap) Join(separator ...string) (str *Object)
Join converts each element into a string then joins them together using the given separator or comma by default.
func (*SliceOfMap) Last ¶ added in v1.2.1
func (p *SliceOfMap) Last() (elem *Object)
Last returns the last element in this Slice as an Object. Object.Nil() == true will be returned if there are no elements in the slice.
func (*SliceOfMap) LastN ¶ added in v1.2.1
func (p *SliceOfMap) LastN(n int) ISlice
LastN returns the last n elements in this Slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.
func (*SliceOfMap) Len ¶ added in v1.2.1
func (p *SliceOfMap) Len() int
Len returns the number of elements in this Slice
func (*SliceOfMap) Less ¶ added in v1.2.1
func (p *SliceOfMap) Less(i, j int) bool
Less returns true if the element indexed by i is less than the element indexed by j.
func (*SliceOfMap) Map ¶ added in v1.2.1
func (p *SliceOfMap) Map(mod func(O) O) ISlice
Map creates a new slice with the modified elements from the lambda.
func (*SliceOfMap) Nil ¶ added in v1.2.1
func (p *SliceOfMap) Nil() bool
Nil tests if this Slice is nil
func (*SliceOfMap) O ¶ added in v1.2.1
func (p *SliceOfMap) O() interface{}
O returns the underlying data structure as is
func (*SliceOfMap) Pair ¶ added in v1.2.1
func (p *SliceOfMap) Pair() (first, second *Object)
Pair simply returns the first and second Slice elements as Objects
func (*SliceOfMap) Pop ¶ added in v1.2.1
func (p *SliceOfMap) Pop() (elem *Object)
Pop modifies this Slice to remove the last element and returns the removed element as an Object.
func (*SliceOfMap) PopN ¶ added in v1.2.1
func (p *SliceOfMap) PopN(n int) (new ISlice)
PopN modifies this Slice to remove the last n elements and returns the removed elements as a new Slice.
func (*SliceOfMap) Prepend ¶ added in v1.2.1
func (p *SliceOfMap) Prepend(elem interface{}) ISlice
Prepend modifies this Slice to add the given element at the begining and returns a reference to this Slice.
func (*SliceOfMap) RefSlice ¶ added in v1.2.1
func (p *SliceOfMap) RefSlice() bool
RefSlice returns true if the underlying implementation is a RefSlice
func (*SliceOfMap) Reverse ¶ added in v1.2.1
func (p *SliceOfMap) Reverse() (new ISlice)
Reverse returns a new Slice with the order of the elements reversed.
func (*SliceOfMap) ReverseM ¶ added in v1.2.1
func (p *SliceOfMap) ReverseM() ISlice
ReverseM modifies this Slice reversing the order of the elements and returns a reference to this Slice.
func (*SliceOfMap) S ¶ added in v1.2.1
func (p *SliceOfMap) S() (slice *StringSlice)
S is an alias to ToStringSlice
func (*SliceOfMap) Select ¶ added in v1.2.1
func (p *SliceOfMap) Select(sel func(O) bool) (new ISlice)
Select creates a new slice with the elements that match the lambda selector.
func (*SliceOfMap) Set ¶ added in v1.2.1
func (p *SliceOfMap) Set(i int, elem interface{}) ISlice
Set the element at the given index location to the given element. Allows for negative notation. Returns a reference to this Slice and swallows any errors.
func (*SliceOfMap) SetE ¶ added in v1.2.1
func (p *SliceOfMap) SetE(i int, elems interface{}) (slice ISlice, err error)
SetE the element at the given index location to the given element. Allows for negative notation. Returns a referenc to this Slice and an error if out of bounds or elem is the wrong type.
func (*SliceOfMap) Shift ¶ added in v1.2.1
func (p *SliceOfMap) Shift() (elem *Object)
Shift modifies this Slice to remove the first element and returns the removed element as an Object.
func (*SliceOfMap) ShiftN ¶ added in v1.2.1
func (p *SliceOfMap) ShiftN(n int) (new ISlice)
ShiftN modifies this Slice to remove the first n elements and returns the removed elements as a new Slice.
func (*SliceOfMap) Single ¶ added in v1.2.1
func (p *SliceOfMap) Single() bool
Single reports true if there is only one element in this Slice.
func (*SliceOfMap) Slice ¶ added in v1.2.1
func (p *SliceOfMap) Slice(indices ...int) ISlice
Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation. Expects nothing, in which case everything is included, or two indices i and j, in which case an inclusive behavior is used such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.
e.g. NewSliceOfMapV(1,2,3).Slice(0, -1) == [1,2,3] && NewSliceOfMapV(1,2,3).Slice(1,2) == [2,3]
func (*SliceOfMap) Sort ¶ added in v1.2.1
func (p *SliceOfMap) Sort() (new ISlice)
Sort returns a new Slice with sorted elements.
func (*SliceOfMap) SortM ¶ added in v1.2.1
func (p *SliceOfMap) SortM() ISlice
SortM modifies this Slice sorting the elements and returns a reference to this Slice.
func (*SliceOfMap) SortReverse ¶ added in v1.2.1
func (p *SliceOfMap) SortReverse() (new ISlice)
SortReverse returns a new Slice sorting the elements in reverse.
func (*SliceOfMap) SortReverseM ¶ added in v1.2.1
func (p *SliceOfMap) SortReverseM() ISlice
SortReverseM modifies this Slice sorting the elements in reverse and returns a reference to this Slice.
func (*SliceOfMap) String ¶ added in v1.2.1
func (p *SliceOfMap) String() string
String returns a string representation of this Slice, implements the Stringer interface
func (*SliceOfMap) Swap ¶ added in v1.2.1
func (p *SliceOfMap) Swap(i, j int)
Swap modifies this Slice swapping the indicated elements.
func (*SliceOfMap) Take ¶ added in v1.2.1
func (p *SliceOfMap) Take(indices ...int) (new ISlice)
Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice. Expects nothing, in which case everything is taken, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Take(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
func (*SliceOfMap) TakeAt ¶ added in v1.2.1
func (p *SliceOfMap) TakeAt(i int) (elem *Object)
TakeAt modifies this Slice removing the elemement at the given index location and returns the removed element as an Object. Allows for negative notation.
func (*SliceOfMap) TakeW ¶ added in v1.2.1
func (p *SliceOfMap) TakeW(sel func(O) bool) (new ISlice)
TakeW modifies this Slice removing the elements that match the lambda selector and returns them as a new Slice.
func (*SliceOfMap) ToIntSlice ¶ added in v1.2.1
func (p *SliceOfMap) ToIntSlice() (slice *IntSlice)
ToIntSlice converts the underlying slice into a *IntSlice
func (*SliceOfMap) ToInterSlice ¶ added in v1.2.1
func (p *SliceOfMap) ToInterSlice() (slice []interface{})
ToInterSlice converts the given slice to a generic []interface{} slice
func (*SliceOfMap) ToInts ¶ added in v1.2.1
func (p *SliceOfMap) ToInts() (slice []int)
ToInts converts the underlying slice into a []int
func (*SliceOfMap) ToStringSlice ¶ added in v1.2.1
func (p *SliceOfMap) ToStringSlice() (slice *StringSlice)
ToStringSlice converts the underlying slice into a *StringSlice
func (*SliceOfMap) ToStrs ¶ added in v1.2.1
func (p *SliceOfMap) ToStrs() (slice []string)
ToStrs converts the underlying slice into a []string slice
func (*SliceOfMap) Union ¶ added in v1.2.1
func (p *SliceOfMap) Union(slice interface{}) (new ISlice)
Union returns a new Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports SliceOfMap, *SliceOfMap, []string or *[]string
func (*SliceOfMap) UnionM ¶ added in v1.2.1
func (p *SliceOfMap) UnionM(slice interface{}) ISlice
UnionM modifies this Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports SliceOfMap, *SliceOfMap, []string or *[]string
func (*SliceOfMap) Uniq ¶ added in v1.2.1
func (p *SliceOfMap) Uniq() (new ISlice)
Uniq returns a new Slice with all non uniq elements removed while preserving element order. Cost for this call vs the UniqM is roughly the same, this one is appending that one dropping.
func (*SliceOfMap) UniqM ¶ added in v1.2.1
func (p *SliceOfMap) UniqM() ISlice
UniqM modifies this Slice to remove all non uniq elements while preserving element order. Cost for this call vs the Uniq is roughly the same, this one is dropping that one appending.
type Str ¶
type Str []rune
Str wraps the Go []rune and implements the Slice interface providing convenience methods on par with rapid development languages.
func A ¶
func A(obj interface{}) *Str
A is an alias to ToStr for brevity
Example ¶
A --------------------------------------------------------------------------------------------------
str := A("test") fmt.Println(str)
Output: test
func NewStr ¶
func NewStr(obj interface{}) *Str
NewStr creates a new *Str which will never be nil Supports: Str *Str, string *string, []byte *[]byte, rune *rune, []rune *[]rune, []string *[]string ...
Example ¶
NewStr --------------------------------------------------------------------------------------------------
str := NewStr("test") fmt.Println(str)
Output: test
func NewStrV ¶
func NewStrV(elems ...interface{}) *Str
NewStrV creates a new *Str from the given variadic elements. Returned *Str will never be nil. Supports: Str *Str, string *string, []byte *[]byte, rune *rune, []rune *[]rune, []string *[]string ...
func ToStr ¶
func ToStr(obj interface{}) *Str
ToStr convert an interface to a *Str type.
Example ¶
ToStr --------------------------------------------------------------------------------------------------
val := ToStr(true) fmt.Println(val)
Output: true
func (*Str) All ¶
All tests if this Slice contains all of the given variadic elements. Incompatible types will return false. Supports: Str *Str, string *string, rune []rune as a string, []byte as string
Example (Contains) ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.All("1", "2"))
Output: true
func (*Str) AllS ¶
AllS tests if this Slice contains all of the given Slice's elements. Incompatible types will return false. Supports: []Str *[]Str, []string *[]string, StringSlice *StringSlice, []rune *[]rune as chars, []byte *[]byte as chars
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.AllS([]string{"1", "2", "3"}))
Output: true
func (*Str) Any ¶
Any tests if this Slice is not empty or optionally if it contains any of the given variadic elements. Incompatible types will return false. Supports: Str *Str, string *string, rune []rune as a string, []byte as string...
Example (Contains) ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.Any("1"))
Output: true
Example (ContainsAny) ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.Any("0", "1"))
Output: true
Example (Empty) ¶
slice := NewStrV() fmt.Println(slice.Any())
Output: false
Example (NotEmpty) ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.Any())
Output: true
func (*Str) AnyS ¶
AnyS tests if this Slice contains any of the given Slice's elements. Incompatible types will return false. Supports: []Str *[]Str, []string *[]string, StringSlice *StringSlice, []rune *[]rune as chars, []byte *[]byte as chars
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.AnyS([]string{"0", "1"}))
Output: true
func (*Str) AnyW ¶
AnyW tests if this Slice contains any that match the lambda selector.
Example ¶
slice := NewStr("123") fmt.Println(slice.AnyW(func(x O) bool { return ExB(x.(Char) == '2') }))
Output: true
func (*Str) Append ¶
Append an element to the end of this Slice and returns a reference to this Slice. Supports: Str *Str, string *string, []byte *[]byte, rune *rune, []rune *[]rune, []string *[]string ...
Example ¶
slice := NewStrV("1").Append("2").Append("3") fmt.Println(slice)
Output: 123
func (*Str) AppendV ¶
AppendV appends the variadic elements to the end of this Slice and returns a reference to this Slice. Supports: Str *Str, string *string, []byte *[]byte, rune *rune, []rune *[]rune, []string *[]string ...
Example ¶
slice := NewStrV("1").AppendV("2", "3") fmt.Println(slice)
Output: 123
func (*Str) Ascii ¶
Ascii converts the string to pure ASCII
Example ¶
Ascii --------------------------------------------------------------------------------------------------
fmt.Println(A("2�gspu�data").Ascii().A())
Output: 2 gspu data
func (*Str) AsciiA ¶
AsciiA converts the string to pure ASCII
Example ¶
AsciiA --------------------------------------------------------------------------------------------------
fmt.Println(A("2�gspu�data").AsciiA())
Output: 2 gspu data
func (*Str) AsciiOnly ¶
AsciiOnly checks to see if this is an ASCII only string
Example ¶
AsciiOnly --------------------------------------------------------------------------------------------------
fmt.Println(A("foo").AsciiOnly())
Output: true
func (*Str) At ¶
At returns the element at the given index location. Allows for negative notation.
Example ¶
fmt.Println(NewStrV("123").At(2).A())
Output: 3
func (*Str) B ¶
B exports the Str as a Go []byte
Example ¶
B --------------------------------------------------------------------------------------------------
fmt.Println(A("foobar").B())
Output: [102 111 111 98 97 114]
func (*Str) Clear ¶
Clear modifies this Slice to clear out all elements and returns a reference to this Slice.
Example ¶
Clear --------------------------------------------------------------------------------------------------
slice := NewStrV("1").Concat([]string{"2", "3"}) fmt.Println(slice.Clear())
Output:
func (*Str) Concat ¶
Concat returns a new Slice by appending the given Slice to this Slice. Supports Str, *Str, []string or *[]string
Example ¶
slice := NewStrV("1").Concat([]string{"2", "3"}) fmt.Println(slice)
Output: 123
func (*Str) ConcatM ¶
ConcatM modifies this Slice by appending the given and returns a reference to this Slice. Supports: Str *Str, string *string, []byte *[]byte, rune *rune, []rune *[]rune, []string *[]string ...
Example ¶
slice := NewStrV("1").ConcatM([]string{"2", "3"}) fmt.Println(slice)
Output: 123
func (*Str) Contains ¶
Contains checks if the given str is contained in this Str. Pass through for strings.Contains
Example ¶
Contains --------------------------------------------------------------------------------------------------
fmt.Println(A("foobar").Contains("foo"))
Output: true
func (*Str) ContainsAny ¶
ContainsAny checks if any of the given chars exist in this Str. Pass through for strings.ContainsAny
Example ¶
ContainsAny --------------------------------------------------------------------------------------------------
fmt.Println(A("foobar").ContainsAny("bob"))
Output: true
func (*Str) ContainsRune ¶
ContainsRune checks if the given rune exists in this Str. Pass through for strings.ContainsRune
Example ¶
ContainsRune --------------------------------------------------------------------------------------------------
fmt.Println(A("foobar").ContainsRune('b'))
Output: true
func (*Str) Copy ¶
Copy returns a new Slice with the indicated range of elements copied from this Slice. Expects nothing, in which case everything is copied, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.Copy())
Output: 123
func (*Str) Count ¶
Count counts the number of non-overlapping instances of substr in this string. Supports: Str, *Str, string, *string, rune, []rune as a string, []byte as string.
Pass through for strings.Count
Example ¶
slice := NewStrV("1", "2", "2") fmt.Println(slice.Count("2"))
Output: 2
func (*Str) CountW ¶
CountW counts the number of elements in this Slice that match the lambda selector.
Example ¶
slice := NewStrV("1", "2", "2") fmt.Println(slice.CountW(func(x O) bool { return ExB(x.(Char) == '2') }))
Output: 2
func (*Str) Drop ¶
Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice. Expects nothing, in which case everything is dropped, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that DropAt(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.Drop(0, 1))
Output: 3
func (*Str) DropAt ¶
DropAt modifies this Slice to delete the element at the given index location. Allows for negative notation. Returns a reference to this Slice.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.DropAt(1))
Output: 13
func (*Str) DropFirst ¶
DropFirst modifies this Slice to delete the first element and returns a reference to this Slice.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.DropFirst())
Output: 23
func (*Str) DropFirstN ¶
DropFirstN modifies this Slice to delete the first n elements and returns a reference to this Slice.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.DropFirstN(2))
Output: 3
func (*Str) DropLast ¶
DropLast modifies this Slice to delete the last element and returns a reference to this Slice.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.DropLast())
Output: 12
func (*Str) DropLastN ¶
DropLastN modifies thi Slice to delete the last n elements and returns a reference to this Slice.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.DropLastN(2))
Output: 1
func (*Str) DropW ¶
DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice. The slice is updated instantly when lambda expression is evaluated not after DropW completes.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.DropW(func(x O) bool { return ExB(Obj(x).ToInt()%2 == 0) }))
Output: 13
func (*Str) Each ¶
Each calls the given lambda once for each element in this Slice, passing in that element as a parameter. Element will be a *Char. Returns a reference to this Slice
Example ¶
NewStrV("1", "2", "3").Each(func(x O) { fmt.Printf("%v", x.(*Char).A()) })
Output: 123
func (*Str) EachE ¶
EachE calls the given lambda once for each element in this Slice, passing in that element as a parameter. Element will be a *Char. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewStrV("1", "2", "3").EachE(func(x O) error { fmt.Printf("%v", x.(*Char)) return nil })
Output: 123
func (*Str) EachI ¶
EachI calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Element will be a *Char. Returns a reference to this Slice
Example ¶
NewStrV("1", "2", "3").EachI(func(i int, x O) { fmt.Printf("%v:%v", i, x.(*Char)) })
Output: 0:11:22:3
func (*Str) EachIE ¶
EachIE calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Element will be a *Char. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewStrV("1", "2", "3").EachIE(func(i int, x O) error { fmt.Printf("%v:%v", i, x.(*Char)) return nil })
Output: 0:11:22:3
func (*Str) EachR ¶
EachR calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Element will be a *Char. Returns a reference to this Slice
Example ¶
NewStrV("1", "2", "3").EachR(func(x O) { fmt.Printf("%v", x.(*Char)) })
Output: 321
func (*Str) EachRE ¶
EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Element will be a *Char. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewStrV("1", "2", "3").EachRE(func(x O) error { fmt.Printf("%v", x.(*Char)) return nil })
Output: 321
func (*Str) EachRI ¶
EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Element will be a *Char. Returns a reference to this Slice
Example ¶
NewStrV("1", "2", "3").EachRI(func(i int, x O) { fmt.Printf("%v:%v", i, x.(*Char)) })
Output: 2:31:20:1
func (*Str) EachRIE ¶
EachRIE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Element will be a *Char. Returns a reference to this Slice and any error from the lambda.
Example ¶
NewStrV("1", "2", "3").EachRIE(func(i int, x O) error { fmt.Printf("%v:%v", i, x.(*Char)) return nil })
Output: 2:31:20:1
func (*Str) Empty ¶
Empty tests if this Slice is empty.
Example ¶
Empty --------------------------------------------------------------------------------------------------
fmt.Println(NewStrV().Empty())
Output: true
func (*Str) Fields ¶
func (p *Str) Fields() (new *StringSlice)
Fields splits the Str around each instance of one or more consecutive white space characters as defined by unicode.IsSpace, returning a Slice of substrings or an empty Slice if only white space is found or the Str is nil or empty.
Example ¶
slice := NewStr("1 2 3") fmt.Println(slice.Fields())
Output: [1 2 3]
func (*Str) FieldsW ¶
func (p *Str) FieldsW(f func(rune) bool) (new *StringSlice)
FieldsW splits the Str where the lambda f returns true, returning a Slice of substrings or an empty Slice if nothing returns true or the Str is nil or empty.
Example ¶
slice := NewStr("1 2 3") fmt.Println(slice.FieldsW(func(x rune) bool { return ExB(x == ' ') }))
Output: [1 2 3]
func (*Str) First ¶
First returns the first element in this Slice as Object. Object.Nil() == true will be returned when there are no elements in the slice.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.First())
Output: 1
func (*Str) FirstN ¶
FirstN returns the first n elements in this slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.FirstN(2))
Output: 12
func (*Str) G ¶
G returns the underlying data structure as a builtin Go type
Example ¶
G --------------------------------------------------------------------------------------------------
fmt.Println(NewStrV("1", "2", "3").G())
Output: 123
func (*Str) HasAnyPrefix ¶
HasAnyPrefix checks if the string has any of the given prefixes
Example ¶
fmt.Println(NewStr("foobar").HasAnyPrefix("foo"))
Output: true
func (*Str) HasAnyPrefixV ¶
HasAnyPrefixV checks if the string has any of the given prefixes
Example ¶
fmt.Println(NewStr("foobar").HasAnyPrefixV("bar", "foo"))
Output: true
func (*Str) HasAnySuffix ¶
HasAnySuffix checks if the string has any of the given prefixes
Example ¶
fmt.Println(NewStr("foobar").HasAnySuffix("bar"))
Output: true
func (*Str) HasAnySuffixV ¶
HasAnySuffixV checks if the string has any of the given prefixes
Example ¶
fmt.Println(NewStr("foobar").HasAnySuffixV("bar", "foo"))
Output: true
func (*Str) HasPrefix ¶
HasPrefix checks if the Str has the given prefix. Pass through to strings.HasPrefix
Example ¶
fmt.Println(NewStr("foobar").HasPrefix("foo"))
Output: true
func (*Str) HasSuffix ¶
HasSuffix checks if the Str has the given prefix. Pass through to strings.HasSuffix
Example ¶
fmt.Println(NewStr("foobar").HasSuffix("bar"))
Output: true
func (*Str) Index ¶
Index returns the index of the first substr in this Str, or -1 if substr is not present. Pass through to strings.Index
Example ¶
slice := NewStrV("1", "2", "2") fmt.Println(slice.Index("2"))
Output: 1
func (*Str) IndexAny ¶
IndexAny returns the index of the first rune in the given elems found, or -1 if not found. Pass through to strings.IndexAny
Example ¶
slice := NewStrV("1", "2", "2") fmt.Println(slice.IndexAny("42"))
Output: 1
func (*Str) IndexChar ¶
IndexChar returns the index of the first instance of char in this Str, or -1 if char is not present. Specifically handles byte, rune and Char
Example ¶
slice := NewStrV("1", "2", "2") fmt.Println(slice.IndexChar("2"))
Output: 1
func (*Str) Insert ¶
Insert modifies this Slice to insert the given element before the element with the given index. Negative indices count backwards from the end of the slice, where -1 is the last element. If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice. Slice is returned for chaining. Invalid index locations will not change the slice.
Example ¶
slice := NewStrV("1", "3") fmt.Println(slice.Insert(1, "2"))
Output: 123
func (*Str) InterSlice ¶
InterSlice returns true if the underlying implementation is a RefSlice
func (*Str) Join ¶
Join converts each element into a string then joins them together using the given separator or comma by default.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.Join())
Output: 1,2,3
func (*Str) Last ¶
Last returns the last element in this Slice as an Object. Object.Nil() == true will be returned if there are no elements in the slice.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.Last())
Output: 3
func (*Str) LastIndex ¶
LastIndex returns the index of the last substr in this Str, or -1 if substr is not present. Pass through to strings.LastIndex
Example ¶
slice := NewStrV("1", "2", "2") fmt.Println(slice.LastIndex("2"))
Output: 2
func (*Str) LastIndexAny ¶
LastIndexAny returns the index of the first rune in the given elems found, or -1 if not found. Pass through to strings.LastIndexAny
Example ¶
slice := NewStrV("1", "2", "2") fmt.Println(slice.LastIndexAny("42"))
Output: 2
func (*Str) LastIndexChar ¶
LastIndexChar returns the index of the first instance of char in this Str, or -1 if char is not present. Specifically handles byte, rune and Char
Example ¶
slice := NewStrV("1", "2", "2") fmt.Println(slice.LastIndexChar("2"))
Output: 2
func (*Str) LastN ¶
LastN returns the last n elements in this Slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.LastN(2))
Output: 23
func (*Str) Len ¶
Len returns the number of elements in this Slice
Example ¶
Len --------------------------------------------------------------------------------------------------
fmt.Println(NewStrV("1", "2", "3").Len())
Output: 3
func (*Str) Less ¶
Less returns true if the element indexed by i is less than the element indexed by j.
Example ¶
Less --------------------------------------------------------------------------------------------------
slice := NewStrV("2", "3", "1") fmt.Println(slice.Less(0, 2))
Output: false
func (*Str) Map ¶
Map creates a new slice with the modified elements from the lambda.
Example ¶
Map --------------------------------------------------------------------------------------------------
slice := NewStrV("1", "2", "3").Map(func(x O) O { return x.(rune) + 1 }) fmt.Println(slice.O())
Output: 234
func (*Str) Nil ¶
Nil tests if this Slice is nil
Example ¶
Nil --------------------------------------------------------------------------------------------------
var slice *Str fmt.Println(slice.Nil())
Output: true
func (*Str) O ¶
func (p *Str) O() interface{}
O returns the underlying data structure as is
Example ¶
O --------------------------------------------------------------------------------------------------
fmt.Println(NewStrV("1", "2", "3"))
Output: 123
func (*Str) Pair ¶
Pair simply returns the first and second Slice elements as Objects
Example ¶
slice := NewStrV("1", "2") first, second := slice.Pair() fmt.Println(first, second)
Output: 1 2
func (*Str) Pop ¶
Pop modifies this Slice to remove the last element and returns the removed element as an Object.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.Pop())
Output: 3
func (*Str) PopN ¶
PopN modifies this Slice to remove the last n elements and returns the removed elements as a new Slice.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.PopN(2))
Output: 23
func (*Str) Prepend ¶
Prepend modifies this Slice to add the given element at the begining and returns a reference to this Slice.
Example ¶
slice := NewStrV("2", "3") fmt.Println(slice.Prepend("1"))
Output: 123
func (*Str) Replace ¶
Replace returns a copy of the string s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string. If n < 0, there is no limit on the number of replacements. Pass through to strings.Replace
Example ¶
slice := NewStrV("2", "3") fmt.Println(slice.Replace("2", "1", -1))
Output: 13
func (*Str) ReplaceAll ¶
ReplaceAll returns a copy of the string s with all non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string. Pass through to strings.ReplaceAll
Example ¶
slice := NewStrV("2", "2", "3") fmt.Println(slice.ReplaceAll("2", "1"))
Output: 113
func (*Str) Reverse ¶
Reverse returns a new Slice with the order of the elements reversed.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.Reverse())
Output: 321
func (*Str) ReverseM ¶
ReverseM modifies this Slice reversing the order of the elements and returns a reference to this Slice.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.ReverseM())
Output: 321
func (*Str) Select ¶
Select creates a new slice with the elements that match the lambda selector.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.Select(func(x O) bool { return ExB(x.(*Char).G() == '2' || x.(*Char).G() == '3') }))
Output: 23
func (*Str) Set ¶
Set the element(s) at the given index location to the given element(s). Allows for negative notation. Returns a reference to this Slice and swallows any errors.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.Set(0, "0"))
Output: 023
func (*Str) SetE ¶
SetE the element(s) at the given index location to the given element. Allows for negative notation. Returns a reference to this Slice and an error if out of bounds or elem is the wrong type.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.SetE(0, "0"))
Output: 023 <nil>
func (*Str) Shift ¶
Shift modifies this Slice to remove the first element and returns the removed element as an Object.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.Shift())
Output: 1
func (*Str) ShiftN ¶
ShiftN modifies this Slice to remove the first n elements and returns the removed elements as a new Slice.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.ShiftN(2))
Output: 12
func (*Str) Single ¶
Single reports true if there is only one element in this Slice.
Example ¶
slice := NewStrV("1") fmt.Println(slice.Single())
Output: true
func (*Str) Slice ¶
Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation. Expects nothing, in which case everything is included, or two indices i and j, in which case an inclusive behavior is used such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.
e.g. NewStrV(1,2,3).Slice(0, -1) == [1,2,3] && NewStrV(1,2,3).Slice(1,2) == [2,3]
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.Slice(1, -1))
Output: 23
func (*Str) Sort ¶
Sort returns a new Slice with sorted elements.
Example ¶
slice := NewStrV("2", "3", "1") fmt.Println(slice.Sort())
Output: 123
func (*Str) SortM ¶
SortM modifies this Slice sorting the elements and returns a reference to this Slice.
Example ¶
slice := NewStrV("2", "3", "1") fmt.Println(slice.SortM())
Output: 123
func (*Str) SortReverse ¶
SortReverse returns a new Slice sorting the elements in reverse.
Example ¶
slice := NewStrV("2", "3", "1") fmt.Println(slice.SortReverse())
Output: 321
func (*Str) SortReverseM ¶
SortReverseM modifies this Slice sorting the elements in reverse and returns a reference to this Slice.
Example ¶
slice := NewStrV("2", "3", "1") fmt.Println(slice.SortReverseM())
Output: 321
func (*Str) Split ¶
func (p *Str) Split(separator ...string) (slice *StringSlice)
Split this Str into all substrings delimited by separator and returns a slice of the substrings. If Str does not contain separator, Split returns a slice of length 1 whose only element is Str. If Str is empty, Split returns an empty slice. separator defaults to comma if not given.
Example ¶
slice := NewStr("1,2,3") fmt.Println(slice.Split())
Output: [1 2 3]
func (*Str) SplitAfter ¶
func (p *Str) SplitAfter(separator ...string) (slice *StringSlice)
SplitAfter splits this Str into all substrings deliniated by separator and returns a slice of the substrings. If Str does not contain separator, Split returns a slice of length 1 whose only element is Str. If Str is empty, Split returns an empty slice. separator defaults to comma if not given.
Example ¶
slice := NewStr("1,2,3") fmt.Println(slice.SplitAfter())
Output: [1, 2, 3]
func (*Str) SplitEscape ¶ added in v1.2.9
func (p *Str) SplitEscape(separator string, escape ...string) (slice *StringSlice)
SplitEscape wraps the Split function handling a possible escape string. When given the escape character will cause the split to be ignored and the escape string to be stripped out
Example ¶
slice := NewStr("1,2,3") fmt.Println(slice.SplitEscape(","))
Output: [1 2 3]
func (*Str) SplitQuotes ¶
func (p *Str) SplitQuotes() (slice *StringSlice, err error)
SplitQuotes splits this Str into substrings starting and ending with double quotes and returns a slice of the substrings. If Str does not contain quotes, Split returns a slice of length 1 whose only element is Str. If Str is empty, Split returns an empty slice. Unmatched quotes throw and error and empty quotes are removed.
Example ¶
SplitQuotes --------------------------------------------------------------------------------------------------
slice := NewStr(`."foo.bar"`) fmt.Println(slice.SplitQuotes())
Output: [. "foo.bar"] <nil>
func (*Str) String ¶
String returns a string representation of this Slice, implements the Stringer interface
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice)
Output: 123
func (*Str) Swap ¶
Swap modifies this Slice swapping the indicated elements.
Example ¶
slice := NewStrV("2", "3", "1") slice.Swap(0, 2) slice.Swap(1, 2) fmt.Println(slice)
Output: 123
func (*Str) Take ¶
Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice. Expects nothing, in which case everything is taken, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Take(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.Take(0, 1))
Output: 12
func (*Str) TakeAt ¶
TakeAt modifies this Slice removing the elemement at the given index location and returns the removed element as an Object. Allows for negative notation.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.TakeAt(1))
Output: 2
func (*Str) TakeW ¶
TakeW modifies this Slice removing the elements that match the lambda selector and returns them as a new Slice.
Example ¶
slice := NewStrV("1", "2", "3") fmt.Println(slice.TakeW(func(x O) bool { return ExB(Obj(x).ToInt()%2 == 0) }))
Output: 2
func (*Str) Title ¶
Title returns a copy of the string s with all Unicode letters that begin words mapped to their title case. BUG(rsc): The rule Title uses for word boundaries does not handle Unicode punctuation properly. Pass through for strings.Title
Example ¶
slice := NewStr("her royal highness") fmt.Println(slice.Title())
Output: Her Royal Highness
func (*Str) ToIntSlice ¶
ToIntSlice converts the underlying slice into a *IntSlice
func (*Str) ToInterSlice ¶
func (p *Str) ToInterSlice() (slice []interface{})
ToInterSlice converts the given slice to a generic []interface{} slice
func (*Str) ToLower ¶
ToLower returns a copy of the Str with all Unicode letters mapped to their lower case.
Example ¶
slice := NewStr("Her Royal Highness") fmt.Println(slice.ToLower())
Output: her royal highness
func (*Str) ToStringSlice ¶
func (p *Str) ToStringSlice() (slice *StringSlice)
ToStringSlice converts the underlying slice into a *StringSlice
func (*Str) ToUpper ¶
ToUpper returns a copy of the Str with all Unicode letters mapped to their upper case.
Example ¶
slice := NewStr("Her Royal Highness") fmt.Println(slice.ToUpper())
Output: HER ROYAL HIGHNESS
func (*Str) Trim ¶
Trim returns a slice of this Str with all leading and trailing Unicode code points contained in the optional string compatible cutset param removed. Cutset defaults to whitespace.
Example ¶
slice := NewStr("Her Royal Highness") fmt.Println(slice.Trim("H"))
Output: er Royal Highness
func (*Str) TrimFunc ¶
TrimFunc returns a slice of this Str with all leading and trailing Unicode code points c satisfying f(c) removed.
Example ¶
slice := NewStr("Her Royal Highness") fmt.Println(slice.TrimFunc(func(x rune) bool { return ExB(x == 'H') }))
Output: er Royal Highness
func (*Str) TrimLeft ¶
TrimLeft returns a slice of this Str with all leading Unicode code points contained in the optional string compatible cutset param removed. Cutset defaults to whitespace.
Example ¶
slice := NewStr("Her Royal Highness") fmt.Println(slice.TrimLeft("H"))
Output: er Royal Highness
func (*Str) TrimLeftFunc ¶
TrimLeftFunc returns a slice of the Str with all leading Unicode code points c satisfying f(c) removed.
Example ¶
slice := NewStr("Her Royal Highness") fmt.Println(slice.TrimLeftFunc(func(x rune) bool { return ExB(x == 'H') }))
Output: er Royal Highness
func (*Str) TrimPrefix ¶
TrimPrefix returns this Str without the leading prefix. If Str doesn't start with prefix, the response is returned unchanged.
Example ¶
slice := NewStr("Her Royal Highness") fmt.Println(slice.TrimPrefix("Her "))
Output: Royal Highness
func (*Str) TrimRight ¶
TrimRight returns a slice of this Str with all leading Unicode code points contained in the optional string compatible cutset param removed. Cutset defaults to whitespace.
Example ¶
slice := NewStr("Her Royal Highness") fmt.Println(slice.TrimRight("s"))
Output: Her Royal Highne
func (*Str) TrimRightFunc ¶
TrimRightFunc returns a slice of the Str with all leading Unicode code points c satisfying f(c) removed.
Example ¶
slice := NewStr("Her Royal Highness") fmt.Println(slice.TrimRightFunc(func(x rune) bool { return ExB(x == 's') }))
Output: Her Royal Highne
func (*Str) TrimSuffix ¶
TrimSuffix returns this Str without the trailing suffix. If Str doesn't end with suffix, the response is returned unchanged.
Example ¶
slice := NewStr("Her Royal Highness") fmt.Println(slice.TrimSuffix(" Highness"))
Output: Her Royal
func (*Str) Union ¶
Union returns a new Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports Str, *Str, []string or *[]string
Example ¶
slice := NewStrV("1", "2") fmt.Println(slice.Union([]string{"2", "3"}))
Output: 123
func (*Str) UnionM ¶
UnionM modifies this Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports Str, *Str, []string or *[]string
Example ¶
slice := NewStrV("1", "2") fmt.Println(slice.UnionM([]string{"2", "3"}))
Output: 123
func (*Str) Uniq ¶
Uniq returns a new Slice with all non uniq elements removed while preserving element order. Cost for this call vs the UniqM is roughly the same, this one is appending that one dropping.
Example ¶
slice := NewStrV("1", "2", "3", "3") fmt.Println(slice.Uniq())
Output: 123
type StringMap ¶
StringMap implements the IMap interface providing a generic way to work with map types including convenience methods on par with rapid development languages. This type is also specifically designed to handle ordered YAML constructs to work with YAML files with minimal structural changes i.e. no mass sorting changes.
func Map ¶
func Map(obj interface{}) (new *StringMap)
Map provides a generic way to work with Map types. It does this by wrapping Go types directly for optimized types thus avoiding reflection processing overhead and making a plethora of Map methods available. Non-optimized types will fall back on reflection to generically handle the type incurring the full 10x reflection processing overhead.
Optimized: map[string]interface{}
Example ¶
Map --------------------------------------------------------------------------------------------------
fmt.Println(Map(map[string]interface{}{"k": "v"}))
Output: &[{k v}]
func NewStringMap ¶
func NewStringMap(obj interface{}) *StringMap
NewStringMap converts the given interface{} into a StringMap
Example ¶
NewStringMap --------------------------------------------------------------------------------------------------
fmt.Println(NewStringMap(map[string]interface{}{"k": "v"}))
Output: &[{k v}]
func NewStringMapV ¶
func NewStringMapV(m ...interface{}) *StringMap
NewStringMapV creates a new empty StringMap if nothing given else converts the given value into a StringMap.
Example ¶
NewStringMapV --------------------------------------------------------------------------------------------------
fmt.Println(NewStringMapV(map[string]interface{}{"k": "v"}))
Output: &[{k v}]
func ToStringMap ¶
func ToStringMap(obj interface{}) *StringMap
ToStringMap converts an interface to a StringMap type. Supports converting yaml string as well.
func ToStringMapE ¶
ToStringMapE converts an interface to a StringMap type. Supports converting yaml string as well. Specifically restricting the number of conversions here to keep it in line with support YAML types.
Example ¶
ToStringMapE --------------------------------------------------------------------------------------------------
fmt.Println(ToStringMapE(map[interface{}]interface{}{"1": "one"}))
Output: &[{1 one}] <nil>
func (*StringMap) Add ¶ added in v1.2.0
Add the value to the map if it doesn't exist or update value if it does
func (*StringMap) Any ¶
Any tests if this Map is not empty or optionally if it contains any of the given variadic keys.
Example ¶
Any --------------------------------------------------------------------------------------------------
m := NewStringMapV(map[string]interface{}{"k": "v"}) fmt.Println(m.Any())
Output: true
func (*StringMap) Clear ¶
Clear modifies this Map to clear out all key-value pairs and returns a reference to this Map.
Example ¶
Clear --------------------------------------------------------------------------------------------------
m := NewStringMapV(map[string]interface{}{"1": "one"}) fmt.Println(m.Clear())
Output: &[]
func (*StringMap) Copy ¶
Copy returns a new Map with the indicated key-value pairs copied from this Map or all if not given.
Example ¶
Copy --------------------------------------------------------------------------------------------------
m := NewStringMapV(map[string]interface{}{"1": "one", "2": "two"}) fmt.Println(m.Copy("1"))
Output: &[{1 one}]
func (*StringMap) Delete ¶
Delete modifies this Map to delete the indicated key-value pair and returns the value from the Map.
Example ¶
Delete --------------------------------------------------------------------------------------------------
m := NewStringMapV(map[string]interface{}{"1": "one"}) fmt.Println(m.Delete("1").O())
Output: one
func (*StringMap) DeleteM ¶
DeleteM modifies this Map to delete the indicated key-value pair and returns a reference to this Map rather than the key-value pair.
Example ¶
DeleteM --------------------------------------------------------------------------------------------------
m := NewStringMapV(map[string]interface{}{"1": "one"}) fmt.Println(m.DeleteM("1"))
Output: &[]
func (*StringMap) Dump ¶
Dump convert the StringMap into a pretty printed yaml string
Example ¶
Dump --------------------------------------------------------------------------------------------------
m := NewStringMapV(map[string]interface{}{"1": "one"}) fmt.Println(m.Dump())
Output: "1": one
func (*StringMap) Exists ¶
Exists checks if the given key exists in this Map.
Example ¶
Exists --------------------------------------------------------------------------------------------------
m := NewStringMapV(map[string]interface{}{"1": "one"}) fmt.Println(m.Exists("1"))
Output: true
func (*StringMap) Generic ¶
Generic returns true if the underlying implementation uses reflection
Example ¶
Generic --------------------------------------------------------------------------------------------------
fmt.Println(NewStringMapV().Generic())
Output: false
func (*StringMap) Get ¶
Get returns the value at the given key location. Returns empty *Object if not found.
Example ¶
Get --------------------------------------------------------------------------------------------------
m := NewStringMapV(map[string]interface{}{"1": "one"}) fmt.Println(m.Get("1").O())
Output: one
func (*StringMap) Keys ¶
Keys returns all the keys in this Map as a ISlice of the key type.
Example ¶
Keys --------------------------------------------------------------------------------------------------
m := NewStringMapV(map[string]interface{}{"1": "one"}) fmt.Println(m.Keys().O())
Output: [1]
func (*StringMap) Len ¶
Len returns the number of elements in this Map.
Example ¶
Len --------------------------------------------------------------------------------------------------
fmt.Println(NewStringMapV().SetM("k", "v").Len())
Output: 1
func (*StringMap) Merge ¶
Merge modifies this Map by overriding its values at selector with the given map where they both exist and returns a reference to this Map. Converting all string maps into *StringMap instances. Note: this function is unable to traverse through lists
Example ¶
Merge --------------------------------------------------------------------------------------------------
fmt.Println(M().Add("1", "two").Merge(M().Add("1", "one")))
Output: &[{1 one}]
func (*StringMap) MergeG ¶
Merge modifies this Map by overriding its values at selector with the given map where they both exist and returns a reference to this Map. Converting all string maps into *StringMap instances. Note: this function is unable to traverse through lists
Example ¶
MergeG --------------------------------------------------------------------------------------------------
fmt.Println(NewStringMapV(map[string]interface{}{"1": "two"}).MergeG(NewStringMapV(map[string]interface{}{"1": "one"})))
Output: map[1:one]
func (*StringMap) O ¶
func (p *StringMap) O() interface{}
O returns the underlying data structure as is.
Example ¶
O --------------------------------------------------------------------------------------------------
fmt.Println(NewStringMapV(map[string]interface{}{"1": "one"}).O())
Output: map[1:one]
func (*StringMap) Query ¶
Query returns the value for the given selector, using jq type selectors. Returns empty *Object if not found.
- `selector` supports dot notation similar to https://stedolan.github.io/jq/manual/#Basicfilters with some caveats
- `params` are the string interpolation paramaters similar to fmt.Sprintf()
- use the \\ character to escape periods that don't separate keys e.g. "[version=1\\.2\\.3]"
Example ¶
Query --------------------------------------------------------------------------------------------------
fmt.Println(ToStringMap("foo:\n bar: 1\n").Query("foo.bar"))
Output: 1
func (*StringMap) QueryE ¶
QueryE returns the value for the given selector, using jq type selectors. Returns empty *Object if not found.
- `selector` supports dot notation similar to https://stedolan.github.io/jq/manual/#Basicfilters with some caveats
- `params` are the string interpolation paramaters similar to fmt.Sprintf()
- use the \\ character to escape periods that don't separate keys e.g. "[version=1\\.2\\.3]"
func (*StringMap) Remove ¶
Remove modifies this Map to delete the given key location, using jq type selectors and returns a reference to this Map rather than the deleted value.
- `selector` supports dot notation similar to https://stedolan.github.io/jq/manual/#Basicfilters with some caveats
- `params` are the string interpolation paramaters similar to fmt.Sprintf()
- use the \\ character to escape periods that don't separate keys e.g. "[version=1\\.2\\.3]"
Example ¶
Remove --------------------------------------------------------------------------------------------------
fmt.Println(ToStringMap("foo:\n bar1: 1\n bar2: 2\n").Remove("foo.bar1"))
Output: &[{foo [{bar2 2}]}]
func (*StringMap) RemoveE ¶
RemoveE modifies this Map to delete the given key location, using jq type selectors and returns a reference to this Map rather than the deleted value.
- `selector` supports dot notation similar to https://stedolan.github.io/jq/manual/#Basicfilters with some caveats
- `params` are the string interpolation paramaters similar to fmt.Sprintf()
- use the \\ character to escape periods that don't separate keys e.g. "[version=1\\.2\\.3]"
func (*StringMap) Set ¶
Set the value for the given key to the given val. Returns true if the key did not yet exist in this Map.
Example ¶
Set --------------------------------------------------------------------------------------------------
fmt.Println(NewStringMapV().Set("key", "value"))
Output: true
func (*StringMap) SetM ¶
SetM the value for the given key to the given val creating map if necessary. Returns a reference to this Map.
Example ¶
SetM --------------------------------------------------------------------------------------------------
fmt.Println(NewStringMapV().SetM("k", "v"))
Output: &[{k v}]
func (*StringMap) ToStringMap ¶
ToStringMap converts the map to a *StringMap
func (*StringMap) ToStringMapG ¶
ToStringMapG converts the map to a Golang map[string]interface{}
func (*StringMap) Update ¶ added in v1.2.0
Update sets the value for the given selector, using jq type selectors. Returns a reference to this Map.
Example ¶
Update --------------------------------------------------------------------------------------------------
fmt.Println(NewStringMapV().Update(".", map[string]interface{}{"1": "one"}))
Output: &[{1 one}]
func (*StringMap) UpdateE ¶ added in v1.2.0
UpdateE sets the value for the given selector, using jq type selectors. Returns a reference to this Map.
func (*StringMap) WriteJSON ¶
WriteJSON converts the *StringMap into a map[string]interface{} then calls json.WriteJSON on it to write it out to disk.
func (*StringMap) WriteYAML ¶
WriteYAML converts the *StringMap into a map[string]interface{} then calls yaml.WriteYAML on it to write it out to disk.
type StringMapBool ¶
StringMapBool implements the Map interface providing a generic way to work with map types including convenience methods on par with rapid development languages.
func NewStringMapBool ¶
func NewStringMapBool(m ...map[string]bool) *StringMapBool
NewStringMapBool creates a new empty StringMapBool if nothing given else simply casts the given map to StringMapBool.
func (*StringMapBool) Any ¶
func (p *StringMapBool) Any(keys ...interface{}) bool
Any tests if this Map is not empty or optionally if it contains any of the given variadic keys.
func (*StringMapBool) Len ¶
func (p *StringMapBool) Len() int
Len returns the number of elements in this Map.
func (*StringMapBool) Set ¶
func (p *StringMapBool) Set(key, val interface{}) bool
Set the value for the given key to the given val. Returns true if the key did not yet exists in this Map.
type StringSlice ¶
type StringSlice []string
StringSlice implements the Slice interface providing a generic way to work with slice types including convenience methods on par with rapid development languages.
func KeysFromSelector ¶
func KeysFromSelector(selector string, params ...interface{}) (keys *StringSlice, err error)
KeysFromSelector splits the given key selectors into individual keys
- `selector` supports dot notation similar to https://stedolan.github.io/jq/manual/#Basicfilters with some caveats
- `params` are the string interpolation paramaters similar to fmt.Sprintf()
func NewStringSlice ¶
func NewStringSlice(slice interface{}) *StringSlice
NewStringSlice creates a new *StringSlice
Example ¶
slice := NewStringSlice([]string{"1", "2", "3"}) fmt.Println(slice)
Output: [1 2 3]
func NewStringSliceV ¶
func NewStringSliceV(elems ...interface{}) *StringSlice
NewStringSliceV creates a new *StringSlice from the given variadic elements; Always returns at least a reference to an empty StringSlice.
Example (Empty) ¶
slice := NewStringSliceV() fmt.Println(slice)
Output: []
Example (Variadic) ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice)
Output: [1 2 3]
func SV ¶
func SV(elems ...interface{}) (new *StringSlice)
SV is an alias for NewStringSliceV for brevity
func ToStringSlice ¶
func ToStringSlice(obj interface{}) *StringSlice
ToStringSlice convert an interface to a StringSlice type.
func ToStringSliceE ¶
func ToStringSliceE(obj interface{}) (val *StringSlice, err error)
ToStringSliceE convert an interface to a StringSlice type.
Example ¶
ToStringSliceE --------------------------------------------------------------------------------------------------
fmt.Println(ToStringSliceE("1"))
Output: [1] <nil>
func (*StringSlice) All ¶ added in v1.1.23
func (p *StringSlice) All(elems ...interface{}) bool
All tests if this Slice contains all the given variadic elements; Incompatible types will return false.
Example (Contains) ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.All("1"))
Output: true
Example (ContainsAll) ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.All("3", "1"))
Output: true
Example (Empty) ¶
All --------------------------------------------------------------------------------------------------
slice := NewStringSliceV() fmt.Println(slice.All())
Output: false
Example (NotEmpty) ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.All())
Output: true
func (*StringSlice) AllS ¶ added in v1.1.23
func (p *StringSlice) AllS(slice interface{}) bool
AllS tests if this Slice contains all of the given Slice's elements; Incompatible types will return false; Supports StringSlice, *StringSlice, []string or *[]string
Example ¶
AllS --------------------------------------------------------------------------------------------------
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.AllS([]string{"2", "1"}))
Output: true
func (*StringSlice) Any ¶
func (p *StringSlice) Any(elems ...interface{}) bool
Any tests if this Slice is not empty or optionally if it contains any of the given variadic elements; Incompatible types will return false.
Example (Contains) ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Any("1"))
Output: true
Example (ContainsAny) ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Any("0", "1"))
Output: true
Example (Empty) ¶
slice := NewStringSliceV() fmt.Println(slice.Any())
Output: false
Example (NotEmpty) ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Any())
Output: true
func (*StringSlice) AnyS ¶
func (p *StringSlice) AnyS(slice interface{}) bool
AnyS tests if this Slice contains any of the given Slice's elements; Incompatible types will return false; Supports StringSlice, *StringSlice, []string or *[]string
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.AnyS([]string{"0", "1"}))
Output: true
func (*StringSlice) AnyW ¶
func (p *StringSlice) AnyW(sel func(O) bool) bool
AnyW tests if this Slice contains any that match the lambda selector.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.AnyW(func(x O) bool { return ExB(x.(string) == "2") }))
Output: true
func (*StringSlice) Append ¶
func (p *StringSlice) Append(elem interface{}) ISlice
Append an element to the end of this Slice and returns a reference to this Slice.
Example ¶
slice := NewStringSliceV("1").Append("2").Append("3") fmt.Println(slice)
Output: [1 2 3]
func (*StringSlice) AppendV ¶
func (p *StringSlice) AppendV(elems ...interface{}) ISlice
AppendV appends the variadic elements to the end of this Slice and returns a reference to this Slice.
Example ¶
slice := NewStringSliceV("1").AppendV("2", "3") fmt.Println(slice)
Output: [1 2 3]
func (*StringSlice) At ¶
func (p *StringSlice) At(i int) (elem *Object)
At returns the element at the given index location; Allows for negative notation.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.At(2))
Output: 3
func (*StringSlice) Clear ¶
func (p *StringSlice) Clear() ISlice
Clear modifies this Slice to clear out all elements and returns a reference to this Slice.
Example ¶
Clear --------------------------------------------------------------------------------------------------
slice := NewStringSliceV("1").Concat([]string{"2", "3"}) fmt.Println(slice.Clear())
Output: []
func (*StringSlice) Concat ¶
func (p *StringSlice) Concat(slice interface{}) (new ISlice)
Concat returns a new Slice by appending the given Slice to this Slice using variadic expansion; Supports StringSlice, *StringSlice, []string or *[]string
Example ¶
slice := NewStringSliceV("1").Concat([]string{"2", "3"}) fmt.Println(slice)
Output: [1 2 3]
func (*StringSlice) ConcatM ¶
func (p *StringSlice) ConcatM(slice interface{}) ISlice
ConcatM modifies this Slice by appending the given Slice using variadic expansion and returns a reference to this Slice. Supports StringSlice, *StringSlice, []string or *[]string
Example ¶
slice := NewStringSliceV("1").ConcatM([]string{"2", "3"}) fmt.Println(slice)
Output: [1 2 3]
func (*StringSlice) Copy ¶
func (p *StringSlice) Copy(indices ...int) (new ISlice)
Copy returns a new Slice with the indicated range of elements copied from this Slice; Expects nothing, in which case everything is copied, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior; Out of bounds indices will be moved within bounds.
An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Copy())
Output: [1 2 3]
func (*StringSlice) Count ¶
func (p *StringSlice) Count(elem interface{}) (cnt int)
Count the number of elements in this Slice equal to the given element.
Example ¶
slice := NewStringSliceV("1", "2", "2") fmt.Println(slice.Count("2"))
Output: 2
func (*StringSlice) CountW ¶
func (p *StringSlice) CountW(sel func(O) bool) (cnt int)
CountW counts the number of elements in this Slice that match the lambda selector.
Example ¶
slice := NewStringSliceV("1", "2", "2") fmt.Println(slice.CountW(func(x O) bool { return ExB(x.(string) == "2") }))
Output: 2
func (*StringSlice) Drop ¶
func (p *StringSlice) Drop(indices ...int) ISlice
Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice; Expects nothing, in which case everything is dropped, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that DropAt(0, -1) includes index -1 as opposed to Go's exclusive behavior; Out of bounds indices will be moved within bounds.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Drop(0, 1))
Output: [3]
func (*StringSlice) DropAt ¶
func (p *StringSlice) DropAt(i int) ISlice
DropAt modifies this Slice to delete the element at the given index location; Allows for negative notation; Returns a reference to this Slice.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.DropAt(1))
Output: [1 3]
func (*StringSlice) DropFirst ¶
func (p *StringSlice) DropFirst() ISlice
DropFirst modifies this Slice to delete the first element and returns a reference to this Slice.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.DropFirst())
Output: [2 3]
func (*StringSlice) DropFirstN ¶
func (p *StringSlice) DropFirstN(n int) ISlice
DropFirstN modifies this Slice to delete the first n elements and returns a reference to this Slice.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.DropFirstN(2))
Output: [3]
func (*StringSlice) DropFirstW ¶ added in v1.2.4
func (p *StringSlice) DropFirstW(sel func(O) bool) ISlice
DropFirstW modifies this Slice to delete the first elements that match the lambda selector and returns a reference to this Slice; The slice is updated instantly when lambda expression is evaluated not after DropFirstW completes.
func (*StringSlice) DropLast ¶
func (p *StringSlice) DropLast() ISlice
DropLast modifies this Slice to delete the last element and returns a reference to this Slice.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.DropLast())
Output: [1 2]
func (*StringSlice) DropLastN ¶
func (p *StringSlice) DropLastN(n int) ISlice
DropLastN modifies thi Slice to delete the last n elements and returns a reference to this Slice.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.DropLastN(2))
Output: [1]
func (*StringSlice) DropW ¶
func (p *StringSlice) DropW(sel func(O) bool) ISlice
DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice; The slice is updated instantly when lambda expression is evaluated not after DropW completes.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.DropW(func(x O) bool { return ExB(Obj(x).ToInt()%2 == 0) }))
Output: [1 3]
func (*StringSlice) Each ¶
func (p *StringSlice) Each(action func(O)) ISlice
Each calls the given lambda once for each element in this Slice, passing in that element as a parameter; Returns a reference to this Slice
Example ¶
NewStringSliceV("1", "2", "3").Each(func(x O) { fmt.Printf("%v", x) })
Output: 123
func (*StringSlice) EachE ¶
func (p *StringSlice) EachE(action func(O) error) (ISlice, error)
EachE calls the given lambda once for each element in this Slice, passing in that element as a parameter; Returns a reference to this Slice and any error from the lambda.
Example ¶
NewStringSliceV("1", "2", "3").EachE(func(x O) error { fmt.Printf("%v", x) return nil })
Output: 123
func (*StringSlice) EachI ¶
func (p *StringSlice) EachI(action func(int, O)) ISlice
EachI calls the given lambda once for each element in this Slice, passing in the index and element as a parameter; Returns a reference to this Slice
Example ¶
NewStringSliceV("1", "2", "3").EachI(func(i int, x O) { fmt.Printf("%v:%v", i, x) })
Output: 0:11:22:3
func (*StringSlice) EachIE ¶
EachIE calls the given lambda once for each element in this Slice, passing in the index and element as a parameter; Returns a reference to this Slice and any error from the lambda.
Example ¶
NewStringSliceV("1", "2", "3").EachIE(func(i int, x O) error { fmt.Printf("%v:%v", i, x) return nil })
Output: 0:11:22:3
func (*StringSlice) EachR ¶
func (p *StringSlice) EachR(action func(O)) ISlice
EachR calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter; Returns a reference to this Slice
Example ¶
NewStringSliceV("1", "2", "3").EachR(func(x O) { fmt.Printf("%v", x) })
Output: 321
func (*StringSlice) EachRE ¶
func (p *StringSlice) EachRE(action func(O) error) (ISlice, error)
EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter; Returns a reference to this Slice and any error from the lambda.
Example ¶
NewStringSliceV("1", "2", "3").EachRE(func(x O) error { fmt.Printf("%v", x) return nil })
Output: 321
func (*StringSlice) EachRI ¶
func (p *StringSlice) EachRI(action func(int, O)) ISlice
EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter; Returns a reference to this Slice
Example ¶
NewStringSliceV("1", "2", "3").EachRI(func(i int, x O) { fmt.Printf("%v:%v", i, x) })
Output: 2:31:20:1
func (*StringSlice) EachRIE ¶
EachRIE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter; Returns a reference to this Slice and any error from the lambda.
Example ¶
NewStringSliceV("1", "2", "3").EachRIE(func(i int, x O) error { fmt.Printf("%v:%v", i, x) return nil })
Output: 2:31:20:1
func (*StringSlice) Empty ¶
func (p *StringSlice) Empty() bool
Empty tests if this Slice is empty.
Example ¶
Empty --------------------------------------------------------------------------------------------------
fmt.Println(NewStringSliceV().Empty())
Output: true
func (*StringSlice) First ¶
func (p *StringSlice) First() (elem *Object)
First returns the first element in this Slice as Object. Object.Nil() == true will be returned when there are no elements in the slice.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.First())
Output: 1
func (*StringSlice) FirstN ¶
func (p *StringSlice) FirstN(n int) ISlice
FirstN returns the first n elements in this slice as a Slice reference to the original; Best effort is used such that as many as can be will be returned up until the request is satisfied.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.FirstN(2))
Output: [1 2]
func (*StringSlice) FirstW ¶ added in v1.2.3
func (p *StringSlice) FirstW(sel func(O) bool) (elem *Object)
FirstW returns the first element in this Slice as an Object where the lamda selector returns true Object.Nil() == true will be returned when there are no elements in the slice that match the lambda
func (*StringSlice) G ¶
func (p *StringSlice) G() []string
G returns the underlying data structure as a builtin Go type
Example ¶
G --------------------------------------------------------------------------------------------------
fmt.Println(NewStringSliceV("1", "2", "3").G())
Output: [1 2 3]
func (*StringSlice) Index ¶
func (p *StringSlice) Index(elem interface{}) (loc int)
Index returns the index of the first element in this Slice where element == elem Returns a -1 if the element was not not found.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Index("2"))
Output: 1
func (*StringSlice) Insert ¶
func (p *StringSlice) Insert(i int, obj interface{}) ISlice
Insert modifies this Slice to insert the given elements before the element(s) with the given index; Negative indices count backwards from the end of the slice, where -1 is the last element; If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice; If a Slice is given all elements will be inserted starting from the beging until the end; Slice is returned for chaining; Invalid index locations will not change the slice.
Example ¶
slice := NewStringSliceV("1", "3") fmt.Println(slice.Insert(1, "2"))
Output: [1 2 3]
func (*StringSlice) InterSlice ¶
func (p *StringSlice) InterSlice() bool
InterSlice returns true if the underlying implementation is a RefSlice
func (*StringSlice) Join ¶
func (p *StringSlice) Join(separator ...string) (str *Object)
Join converts each element into a string then joins them together using the given separator or comma by default.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Join())
Output: 1,2,3
func (*StringSlice) Last ¶
func (p *StringSlice) Last() (elem *Object)
Last returns the last element in this Slice as an Object; Object.Nil() == true will be returned if there are no elements in the slice.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Last())
Output: 3
func (*StringSlice) LastN ¶
func (p *StringSlice) LastN(n int) ISlice
LastN returns the last n elements in this Slice as a Slice reference to the original; Best effort is used such that as many as can be will be returned up until the request is satisfied.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.LastN(2))
Output: [2 3]
func (*StringSlice) Len ¶
func (p *StringSlice) Len() int
Len returns the number of elements in this Slice
Example ¶
Len --------------------------------------------------------------------------------------------------
fmt.Println(NewStringSliceV("1", "2", "3").Len())
Output: 3
func (*StringSlice) Less ¶
func (p *StringSlice) Less(i, j int) bool
Less returns true if the element indexed by i is less than the element indexed by j.
Example ¶
slice := NewStringSliceV("2", "3", "1") fmt.Println(slice.Less(0, 2))
Output: false
func (*StringSlice) Map ¶
func (p *StringSlice) Map(mod func(O) O) ISlice
Map creates a new slice with the modified elements from the lambda.
Example ¶
Map --------------------------------------------------------------------------------------------------
slice := NewStringSliceV("1", "2", "3") slice = slice.Map(func(x O) O { return ToStr(ToInt(x.(string)) + 1).A() }).S() fmt.Println(slice.G())
Output: [2 3 4]
func (*StringSlice) Nil ¶
func (p *StringSlice) Nil() bool
Nil tests if this Slice is nil
Example ¶
Nil --------------------------------------------------------------------------------------------------
var slice *StringSlice fmt.Println(slice.Nil())
Output: true
func (*StringSlice) O ¶
func (p *StringSlice) O() interface{}
O returns the underlying data structure as is
Example ¶
O --------------------------------------------------------------------------------------------------
fmt.Println(NewStringSliceV("1", "2", "3"))
Output: [1 2 3]
func (*StringSlice) Pair ¶
func (p *StringSlice) Pair() (first, second *Object)
Pair simply returns the first and second Slice elements as Objects
Example ¶
slice := NewStringSliceV("1", "2") first, second := slice.Pair() fmt.Println(first, second)
Output: 1 2
func (*StringSlice) Pop ¶
func (p *StringSlice) Pop() (elem *Object)
Pop modifies this Slice to remove the last element and returns the removed element as an Object.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Pop())
Output: 3
func (*StringSlice) PopN ¶
func (p *StringSlice) PopN(n int) (new ISlice)
PopN modifies this Slice to remove the last n elements and returns the removed elements as a new Slice.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.PopN(2))
Output: [2 3]
func (*StringSlice) Prepend ¶
func (p *StringSlice) Prepend(elem interface{}) ISlice
Prepend modifies this Slice to add the given element at the begining and returns a reference to this Slice.
Example ¶
slice := NewStringSliceV("2", "3") fmt.Println(slice.Prepend("1"))
Output: [1 2 3]
func (*StringSlice) RefSlice ¶
func (p *StringSlice) RefSlice() bool
RefSlice returns true if the underlying implementation is a RefSlice
func (*StringSlice) Reverse ¶
func (p *StringSlice) Reverse() (new ISlice)
Reverse returns a new Slice with the order of the elements reversed.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Reverse())
Output: [3 2 1]
func (*StringSlice) ReverseM ¶
func (p *StringSlice) ReverseM() ISlice
ReverseM modifies this Slice reversing the order of the elements and returns a reference to this Slice.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.ReverseM())
Output: [3 2 1]
func (*StringSlice) S ¶
func (p *StringSlice) S() (slice *StringSlice)
S is an alias to ToStringSlice
func (*StringSlice) Select ¶
func (p *StringSlice) Select(sel func(O) bool) (new ISlice)
Select creates a new slice with the elements that match the lambda selector.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Select(func(x O) bool { return ExB(x.(string) == "2" || x.(string) == "3") }))
Output: [2 3]
func (*StringSlice) Set ¶
func (p *StringSlice) Set(i int, elem interface{}) ISlice
Set the element(s) at the given index location to the given element(s); Allows for negative notation. Returns a reference to this Slice and swallows any errors.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Set(0, "0"))
Output: [0 2 3]
func (*StringSlice) SetE ¶
func (p *StringSlice) SetE(i int, elems interface{}) (ISlice, error)
SetE the element(s) at the given index location to the given element(s); Allows for negative notation. Returns a referenc to this Slice and an error if out of bounds or elem is the wrong type.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.SetE(0, "0"))
Output: [0 2 3] <nil>
func (*StringSlice) Shift ¶
func (p *StringSlice) Shift() (elem *Object)
Shift modifies this Slice to remove the first element and returns the removed element as an Object.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Shift())
Output: 1
func (*StringSlice) ShiftN ¶
func (p *StringSlice) ShiftN(n int) (new ISlice)
ShiftN modifies this Slice to remove the first n elements and returns the removed elements as a new Slice.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.ShiftN(2))
Output: [1 2]
func (*StringSlice) Single ¶
func (p *StringSlice) Single() bool
Single reports true if there is only one element in this Slice.
Example ¶
slice := NewStringSliceV("1") fmt.Println(slice.Single())
Output: true
func (*StringSlice) Slice ¶
func (p *StringSlice) Slice(indices ...int) ISlice
Slice returns a range of elements from this Slice as a Slice reference to the original; Allows for negative notation. Expects nothing, in which case everything is included, or two indices i and j, in which case an inclusive behavior is used such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior; Out of bounds indices will be moved within bounds;
An empty Slice is returned if indicies are mutually exclusive or nothing can be returned;
e.g. NewStringSliceV(1,2,3).Slice(0, -1) == [1,2,3] && NewStringSliceV(1,2,3).Slice(1,2) == [2,3]
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Slice(1, -1))
Output: [2 3]
func (*StringSlice) Sort ¶
func (p *StringSlice) Sort() (new ISlice)
Sort returns a new Slice with sorted elements.
Example ¶
slice := NewStringSliceV("2", "3", "1") fmt.Println(slice.Sort())
Output: [1 2 3]
func (*StringSlice) SortM ¶
func (p *StringSlice) SortM() ISlice
SortM modifies this Slice sorting the elements and returns a reference to this Slice.
Example ¶
slice := NewStringSliceV("2", "3", "1") fmt.Println(slice.SortM())
Output: [1 2 3]
func (*StringSlice) SortReverse ¶
func (p *StringSlice) SortReverse() (new ISlice)
SortReverse returns a new Slice sorting the elements in reverse.
Example ¶
slice := NewStringSliceV("2", "3", "1") fmt.Println(slice.SortReverse())
Output: [3 2 1]
func (*StringSlice) SortReverseM ¶
func (p *StringSlice) SortReverseM() ISlice
SortReverseM modifies this Slice sorting the elements in reverse and returns a reference to this Slice.
Example ¶
slice := NewStringSliceV("2", "3", "1") fmt.Println(slice.SortReverseM())
Output: [3 2 1]
func (*StringSlice) String ¶
func (p *StringSlice) String() string
String returns a string representation of this Slice, implements the Stringer interface
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice)
Output: [1 2 3]
func (*StringSlice) Swap ¶
func (p *StringSlice) Swap(i, j int)
Swap modifies this Slice swapping the indicated elements.
Example ¶
slice := NewStringSliceV("2", "3", "1") slice.Swap(0, 2) slice.Swap(1, 2) fmt.Println(slice)
Output: [1 2 3]
func (*StringSlice) Take ¶
func (p *StringSlice) Take(indices ...int) (new ISlice)
Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice; Expects nothing, in which case everything is taken, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Take(0, -1) includes index -1 as opposed to Go's exclusive behavior; Out of bounds indices will be moved within bounds.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.Take(0, 1))
Output: [1 2]
func (*StringSlice) TakeAt ¶
func (p *StringSlice) TakeAt(i int) (elem *Object)
TakeAt modifies this Slice removing the elemement at the given index location and returns the removed element as an Object; Allows for negative notation.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.TakeAt(1))
Output: 2
func (*StringSlice) TakeW ¶
func (p *StringSlice) TakeW(sel func(O) bool) (new ISlice)
TakeW modifies this Slice removing the elements that match the lambda selector and returns them as a new Slice.
Example ¶
slice := NewStringSliceV("1", "2", "3") fmt.Println(slice.TakeW(func(x O) bool { return ExB(Obj(x).ToInt()%2 == 0) }))
Output: [2]
func (*StringSlice) ToIntSlice ¶
func (p *StringSlice) ToIntSlice() (slice *IntSlice)
ToIntSlice converts the underlying slice into a *IntSlice
func (*StringSlice) ToInterSlice ¶
func (p *StringSlice) ToInterSlice() (slice []interface{})
ToInterSlice converts the given slice to a generic []interface{} slice
func (*StringSlice) ToInts ¶
func (p *StringSlice) ToInts() (slice []int)
ToInts converts the underlying slice into a []int
func (*StringSlice) ToStringSlice ¶
func (p *StringSlice) ToStringSlice() (slice *StringSlice)
ToStringSlice converts the underlying slice into a *StringSlice
func (*StringSlice) ToStrs ¶
func (p *StringSlice) ToStrs() (slice []string)
ToStrs converts the underlying slice into a []string slice
func (*StringSlice) Union ¶
func (p *StringSlice) Union(slice interface{}) (new ISlice)
Union returns a new Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order; Supports StringSlice, *StringSlice, []string or *[]string
Example ¶
slice := NewStringSliceV("1", "2") fmt.Println(slice.Union([]string{"2", "3"}))
Output: [1 2 3]
func (*StringSlice) UnionM ¶
func (p *StringSlice) UnionM(slice interface{}) ISlice
UnionM modifies this Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order; Supports StringSlice, *StringSlice, []string or *[]string
Example ¶
slice := NewStringSliceV("1", "2") fmt.Println(slice.UnionM([]string{"2", "3"}))
Output: [1 2 3]
func (*StringSlice) Uniq ¶
func (p *StringSlice) Uniq() (new ISlice)
Uniq returns a new Slice with all non uniq elements removed while preserving element order; Cost for this call vs the UniqM is roughly the same, this one is appending that one dropping.
Example ¶
slice := NewStringSliceV("1", "2", "3", "3") fmt.Println(slice.Uniq())
Output: [1 2 3]
func (*StringSlice) UniqM ¶
func (p *StringSlice) UniqM() ISlice
UniqM modifies this Slice to remove all non uniq elements while preserving element order; Cost for this call vs the Uniq is roughly the same, this one is dropping that one appending.
Example ¶
slice := NewStringSliceV("1", "2", "3", "3") fmt.Println(slice.UniqM())
Output: [1 2 3]
Notes ¶
Bugs ¶
The rule Title uses for word boundaries does not handle Unicode punctuation properly. Pass through for strings.Title
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
pkg
|
|
arch
Package arch provides archive and compression helper functions
|
Package arch provides archive and compression helper functions |
arch/tar
Package tar provides helper functions for tar archives
|
Package tar provides helper functions for tar archives |
arch/zip
Package zip provides create and extract implementations
|
Package zip provides create and extract implementations |
buf
Package buf provides various specialized buffers
|
Package buf provides various specialized buffers |
buf/runes
Package runes provides a simpler rune scanner for lexers.
|
Package runes provides a simpler rune scanner for lexers. |
enc
Package enc provides encoding/decoding helper functions
|
Package enc provides encoding/decoding helper functions |
enc/bin
Package bin provides some low level binary protocol helpers
|
Package bin provides some low level binary protocol helpers |
enc/json
Package json provides helper functions for working with json
|
Package json provides helper functions for working with json |
enc/unit
Package unit provides some helpful unit conversions
|
Package unit provides some helpful unit conversions |
enc/yaml
Package yaml provides helper functions for working with yaml
|
Package yaml provides helper functions for working with yaml |
errs
Package errs provides a common set of error for the pkg n
|
Package errs provides a common set of error for the pkg n |
futil
Package futil provides helper functions for interacting with files
|
Package futil provides helper functions for interacting with files |
net
Package net provides simple networking helper functions
|
Package net provides simple networking helper functions |
net/agent
Package agent provides simple agent helper functions
|
Package agent provides simple agent helper functions |
net/mech
Package mech provides some simple automation for working with web sites
|
Package mech provides some simple automation for working with web sites |
opt
Package opt provides common properties for custom types and support for the options pattern.
|
Package opt provides common properties for custom types and support for the options pattern. |
structs
Package structs provides reflection based utilities for working with structs.
|
Package structs provides reflection based utilities for working with structs. |
sys
Package sys provides os level helper functions for interacting with the system
|
Package sys provides os level helper functions for interacting with the system |
term
Package term provides TTY helper functions for prompting for passwords etc...
|
Package term provides TTY helper functions for prompting for passwords etc... |
term/color
Package color provides basic terminal color output via ANSI Escape Codes https://misc.flogisoft.com/bash/tip_colors_and_formatting
|
Package color provides basic terminal color output via ANSI Escape Codes https://misc.flogisoft.com/bash/tip_colors_and_formatting |
time
Package time provides simple time helper functions
|
Package time provides simple time helper functions |
tmpl
Package tmpl does simple template substitutions fast
|
Package tmpl does simple template substitutions fast |