n

package module
v2.0.37+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2019 License: MIT Imports: 15 Imported by: 1

README

n

Numerable is a collection of missing Go convenience functions reminiscent of Ruby/C#. I love the elegance of Ruby's plethera of descriptive chainable methods while C# has some awesome deferred execution. Why not stay with Ruby or C# then? Well I like Go's ability to generate a single statically linked binary, Go's concurrancy model, Go's performance, Go's package ecosystem and Go's tool chain. This package was created to reduce the friction I had adopting Go as my primary language of choice. n is intended to reduce the coding verbosity required by Go via convenience functions and the Numerable types.

https://godoc.org/github.com/phR0ze/n

Table of Contents

Numerable

Numerable provide a way to generically handle various types in Go with the convenience methods you would expect similar to Ruby or C#, making life a little easier. Since I'm using Reflection to accomplish this it obviously comes at a cost, which in some cases isn't worth it. However, as found in many cases, the actual work being done far out ways the bookkeeping overhead incurred with the use of reflection. Other times the speed and convenience of not having to re-implement a Delete or Contains function for the millionth time far out weighs the performance cost.

Numerable Requirements

The Numerable interface and types implementing it are designed to accomplish the following requirements:

  • Chaining - the ability to call additional methods via a returned reference to the type
  • Brevity - keep the naming as concise as possible while not infringing on clarity
  • Clarity - keep the naming as unambiguous as possible while not infringing on brevity
  • Performance - keep convenience functions as performant as possible while calling out significant costs
  • Speed - provide convenience function parity with rapid development languages
  • Comfort - use naming and concepts in similar ways to popular languages

Background

Efficiency is paramount when developing. We want to develop quickly, be able to pick up someone else's code and understand it quickly and yet still have our code execute quickly. The industry uses terms like Code Readability, Code Reuse, Code Maintainablity, Code Clarity, Code Performance to describe this. These best practices have developed over a long history swinging wildly from one end of the spectrum to the other and back again.

Development started in the 1950's with super low level langauges and little readability, clarity or maintainability but awesome performance (relatively speaking). This was far left on the efficiency spectrum of performance vs rapid development. Coding was tedious and laborious. Then came the systems level languages like C (1970's) and C++ (1980's) that began shifting a little more to the right with more abstraction and convenience functions to reuse algorithums and code thus higher development speed. This worked so well that higher level languages with even more abstractions and even more convenience functions were created like Java (1990's), Ruby (1990's), Python (1990's), C# (2000's) etc... all chasing this dream of optimal efficiency but swinging away from performance toward rapid development on the far right. The inventors of Golang felt that the trade off with current languages was unacceptable and designed Go to address the problem. To their credit they were able to get a pretty good mix between performance and speed of development.

Resources

Language Popularity

Performance

Performance is a concern in handling generics as the Golang inventors rightly pointed out. Go was targeted as a systems language yet also noted as being a rapid development language. Certainly in my experience it is being used in place of rapid development languages such as Ruby, Python and C# but also Java as well. Generics are so vital to rapid development that a 10x cost may be worth it.

Benchmarks Game
Test Py 3.7.2 Go 1.12 C# 2.2.1 Ruby 2.6 Go vs Py
Binary Trees 81.74s 26.94s 7.73s 64.97s 3.03x
Fannkuch-redux 482.90s 18.07s 17.46s 545.63s 26.72x
Fasta 63.18s 2.07s 2.27s 63.32s 30.52x
K-nucleotide 73.60s 11.98s 5.48s 189.81s 6.14x
Mandlebrot 265.56s 5.50s 5.54s 452.81s 48.28x
N-Body 819.56s 21.19s 21.41s 387.73s 38.68x
Pidigits 3.33s 2.03s 0.84s 1.71s 1.64x
Regex-Redux 17.28s 29.13s 2.22s 23.58 -1.67x
Reverse Comple 16.19s 3.98s 2.99s 23.09s 4.05x
Spectral-Norm 170.52s 3.94s 4.07s 237.96s 43.28x
Reflection Assisted - 2x cost

By storing items as a reflect.ValueOf we can use reflection to assist in handling generic types but then type assert for all common types to provide those types with only a 2x cost vs the 10x cost that falling back on pure reflection for unhandled types will cost.

6 nines slice costs 0.02ns while this implementation costs 0.02ns:

func (q *NSlice) Append(item interface{}) *NSlice {
	if q.Nil() {
		nq := Slicef(item)
		if !nq.Nil() {
			*q = *nq
		}
	} else {
		switch slice := q.v.Interface().(type) {
		case []int:
			if x, ok := item.(int); ok {
				slice = append(slice, x)
			} else {
				panic(fmt.Sprintf("can't insert type '%T' into []string", item))
			}
		default:
			panic("unsupported")
			item := reflect.ValueOf(item)
			*q.v = reflect.Append(*q.v, item)
		}
	}
	return q
}
Pure Reflection - 10x cost

Storing the items as a reflect.ValueOf is the most elegant and obvious way of doing this and as eveyone knows incurs the standard 10x reflection cost.

6 nines slice costs 0.01ns while this implementation costs 0.10ns:

func (n *NSlice) Append(items ...interface{}) *NSlice {
	if len(items) > 0 {
		if n.Nil() {
			*n = *(Slicef(items...))
		} else {
			for i := 0; i < len(items); i++ {
				item := reflect.ValueOf(items[i])
				*n.v = reflect.Append(*n.v, item)
			}
		}
	}
	return n
}
Generic Slice - 18x cost

Storing the items as a []interface{} avoids the upfront 10x reflection cost but then requires looping over the entire set of items and performing a type assertion on each to return the final typed slice which resulted in an 18x cost even though reflection wasn't used.

6 nines slice costs 0.01ns while this implementation costs 0.20ns:

func (n *NSlice) Append(items ...interface{}) *NSlice {
	if n.Nil() {
		*n = *(Slicef(items))
	} else {
		for _, item := range items {
			n.o = append(n.o, item)
		}
	}
	return n
}

Deferred Execution

C# has some excellent defferred execution and the concept is really slick. I haven't found a great need for it yet and thus haven't gotten around to it, but it's fun to research how it's done.

Iterator Pattern

Since Numerable is fundamentally based on the notion of iterables, iterating over collections, that was the first challenge to solve. How do you generically iterate over all primitive Go types.

I implemented the iterator pattern based off of the iterator closure pattern disscussed by blog https://ewencp.org/blog/golang-iterators/index.htm mainly for syntactic style. Some sources indicate that the closure style iterator is about 3x slower than normal. However my own benchmarking was much closer coming in at only 33% hit. Even at 3x slower I'm willing to take that hit for convenience in most case.

Changing the order in which my benchmarks run seems to affect the time (caching?). At any rate on average I'm seeing only about a 33.33% performance hit. 33% in nested large data sets may impact performance in some cases but I'm betting in most cases performance will be dominated by actual work and not looping overhead.

# 36% slower to use Each function
BenchmarkEach-16               	       1	1732989848 ns/op
BenchmarkArrayIterator-16      	       1	1111445479 ns/op
BenchmarkClosureIterator-16    	       1	1565197326 ns/op

# 25% slower to use Each function
BenchmarkArrayIterator-16      	       1	1210185264 ns/op
BenchmarkClosureIterator-16    	       1	1662226578 ns/op
BenchmarkEach-16               	       1	1622667779 ns/op

# 30% slower to use Each function
BenchmarkClosureIterator-16    	       1	1695826796 ns/op
BenchmarkArrayIterator-16      	       1	1178876072 ns/op
BenchmarkEach-16               	       1	1686159938 ns/op

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 Slice as input or returns a Slice.

• 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

Examples

Constants

This section is empty.

Variables

View Source
var Break = errors.New("break")

Break is a brevity helper for breaking out of lambda loops

View Source
var (
	// ReGraphicalOnly is a regex to filter on graphical runes only
	ReGraphicalOnly = regexp.MustCompile(`[^[:graph:]]+`)
)

Functions

func B

func B(obj interface{}) bool

B converts an interface to a bool type.

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

func EitherStr(first, second string) string

EitherStr returns the first string if not empty else the second

Example
fmt.Println(EitherStr("", "default"))
Output:

default

func ExB

func ExB(exp bool) bool

ExB avoids Go's gastly 4 line monstrosity required to implement this providing instead a single clean line of code for lambdas.

func IdxFromSelector

func IdxFromSelector(selector string, size int) (i int, k, v string, err error)

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

func MergeStringMap(a, b map[string]interface{}, location ...string) map[string]interface{}

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 R

func R(obj interface{}) rune

R is an alias to ToRune for brevity

func Range

func Range(min, max int) []int

Range creates slice of the given range of numbers inclusive

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 SetOnFalseB

func SetOnFalseB(result *bool, value, exp bool) bool

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 SetOnTrueB

func SetOnTrueB(result *bool, value, exp bool) bool

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

func ToBoolE(obj interface{}) (val bool, err error)

ToBoolE converts an interface to a bool type.

Example

ToBoolE --------------------------------------------------------------------------------------------------

fmt.Println(ToBoolE(1))
Output:

true <nil>

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

func ToFloat32E(obj interface{}) (val float32, err error)

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

func ToFloat64E(obj interface{}) (val float64, err error)

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 ToIntE

func ToIntE(obj interface{}) (val int, err error)

ToIntE convert an interface to an int type.

Example

ToIntE --------------------------------------------------------------------------------------------------

fmt.Println(ToIntE("1"))
Output:

1 <nil>

func ToRune

func ToRune(obj interface{}) rune

ToRune convert an interface to a rune type.

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. Supports converting yaml string as well.

func ToStringSliceG

func ToStringSliceG(obj interface{}) (val []string)

ToStringSliceG convert an interface to a []string type.

func ToStringSliceGE

func ToStringSliceGE(obj interface{}) (val []string, err error)

ToStringSliceGE convert an interface to a []string type.

Example

ToStringSliceGE --------------------------------------------------------------------------------------------------

fmt.Println(ToStringSliceGE("1"))
Output:

[1] <nil>

func YamlCont

func YamlCont(obj interface{}) bool

YamlCont checks if the given value is a valid Yaml container

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 C

func C(obj interface{}) *Char

C is an alias to ToChar for brevity

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) A

func (p *Char) A() string

A is an alias of String for brevity

func (*Char) Equal

func (p *Char) Equal(obj interface{}) bool

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) G

func (p *Char) G() rune

G returns the underlying data structure as a builtin Go type

func (*Char) Less

func (p *Char) Less(obj interface{}) bool

Less returns true if the given *Char is less than this *Char.

Example

Less --------------------------------------------------------------------------------------------------

fmt.Println(NewChar('3').Less('2'))
Output:

false

func (*Char) Nil

func (p *Char) Nil() bool

Nil tests if the object is nil

func (*Char) Null

func (p *Char) Null() bool

Null tests if the char is a rune(0)

func (*Char) O

func (p *Char) O() interface{}

O returns the underlying data structure as is

func (*Char) String

func (p *Char) String() string

String returns a string representation of the Object, implements Stringer interface.

Example

String --------------------------------------------------------------------------------------------------

char := NewChar('3')
fmt.Println(char)
Output:

3

type FloatMapBool

type FloatMapBool map[float64]bool

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) A

func (p *FloatSlice) A() string

A is an alias to String for brevity

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{}) Slice

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{}) Slice

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() Slice

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 Slice)

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{}) Slice

ConcatM modifies this Slice by appending the given Slice using variadic expansion and returns a reference to this Slice. 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 Slice)

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) Slice

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) Slice

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() Slice

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) Slice

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() Slice

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) Slice

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) Slice

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)) Slice

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) (Slice, 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)) Slice

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

func (p *FloatSlice) EachIE(action func(int, O) error) (Slice, error)

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)) Slice

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) (Slice, 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)) Slice

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

func (p *FloatSlice) EachRIE(action func(int, O) error) (Slice, error)

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) Slice

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{}) Slice

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) Slice

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) 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 Slice)

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{}) Slice

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 Slice)

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() Slice

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) S

func (p *FloatSlice) S() (slice *StringSlice)

S is an alias to ToStringSlice

func (*FloatSlice) SG

func (p *FloatSlice) SG() (slice []string)

SG is an alias to ToStringSliceG

func (*FloatSlice) Select

func (p *FloatSlice) Select(sel func(O) bool) (new Slice)

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{}) Slice

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{}) (Slice, 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 Slice)

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) 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. 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 Slice)

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() Slice

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 Slice)

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() Slice

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 Slice)

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 Slice)

TakeW modifies this Slice removing the elements that match the lambda selector and returns them as a new Slice.

func (*FloatSlice) ToInterSlice

func (p *FloatSlice) ToInterSlice() (slice []interface{})

ToInterSlice converts the given slice to a generic []interface{} slice

func (*FloatSlice) ToStringSlice

func (p *FloatSlice) ToStringSlice() (slice *StringSlice)

ToStringSlice converts the underlying slice into a *StringSlice

func (*FloatSlice) ToStringSliceG

func (p *FloatSlice) ToStringSliceG() (slice []string)

ToStringSliceG converts the underlying slice into a []string slice

func (*FloatSlice) Union

func (p *FloatSlice) Union(slice interface{}) (new Slice)

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{}) Slice

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 Slice)

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() Slice

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 IntMapBool

type IntMapBool map[int]bool

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

func ToIntSliceE(obj interface{}) (val *IntSlice, err error)

ToIntSliceE convert an interface to a IntSlice type.

Example

ToIntSliceE --------------------------------------------------------------------------------------------------

fmt.Println(ToIntSliceE("1"))
Output:

[1] <nil>

func (*IntSlice) A

func (p *IntSlice) A() string

A is an alias to String for brevity

func (*IntSlice) Any

func (p *IntSlice) 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 := 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

func (p *IntSlice) AnyS(slice interface{}) bool

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

func (p *IntSlice) AnyW(sel func(O) bool) bool

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

func (p *IntSlice) Append(elem interface{}) Slice

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

func (p *IntSlice) AppendV(elems ...interface{}) Slice

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

func (p *IntSlice) At(i int) (elem *Object)

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

func (p *IntSlice) Clear() Slice

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

func (p *IntSlice) Concat(slice interface{}) (new Slice)

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

func (p *IntSlice) ConcatM(slice interface{}) Slice

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

func (p *IntSlice) Copy(indices ...int) (new Slice)

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

func (p *IntSlice) Count(elem interface{}) (cnt int)

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

func (p *IntSlice) CountW(sel func(O) bool) (cnt int)

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

func (p *IntSlice) Drop(indices ...int) Slice

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

func (p *IntSlice) DropAt(i int) Slice

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

func (p *IntSlice) DropFirst() Slice

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

func (p *IntSlice) DropFirstN(n int) Slice

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

func (p *IntSlice) DropLast() Slice

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

func (p *IntSlice) DropLastN(n int) Slice

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

func (p *IntSlice) DropW(sel func(O) bool) Slice

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

func (p *IntSlice) Each(action func(O)) Slice

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

func (p *IntSlice) EachE(action func(O) error) (Slice, 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
NewIntSliceV(1, 2, 3).EachE(func(x O) error {
	fmt.Printf("%v", x)
	return nil
})
Output:

123

func (*IntSlice) EachI

func (p *IntSlice) EachI(action func(int, O)) Slice

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

func (p *IntSlice) EachIE(action func(int, O) error) (Slice, error)

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

func (p *IntSlice) EachR(action func(O)) Slice

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

func (p *IntSlice) EachRE(action func(O) error) (Slice, 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
NewIntSliceV(1, 2, 3).EachRE(func(x O) error {
	fmt.Printf("%v", x)
	return nil
})
Output:

321

func (*IntSlice) EachRI

func (p *IntSlice) EachRI(action func(int, O)) Slice

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

func (p *IntSlice) EachRIE(action func(int, O) error) (Slice, error)

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

func (p *IntSlice) Empty() bool

Empty tests if this Slice is empty.

Example

Empty --------------------------------------------------------------------------------------------------

fmt.Println(NewIntSliceV().Empty())
Output:

true

func (*IntSlice) First

func (p *IntSlice) 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 := NewIntSliceV(1, 2, 3)
fmt.Println(slice.First())
Output:

1

func (*IntSlice) FirstN

func (p *IntSlice) FirstN(n int) Slice

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

func (p *IntSlice) G() []int

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

func (p *IntSlice) 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 := NewIntSliceV(1, 2, 3)
fmt.Println(slice.Index(2))
Output:

1

func (*IntSlice) Insert

func (p *IntSlice) Insert(i int, obj interface{}) Slice

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

func (p *IntSlice) InterSlice() bool

InterSlice returns true if the underlying implementation is a RefSlice

func (*IntSlice) Join

func (p *IntSlice) 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 := NewIntSliceV(1, 2, 3)
fmt.Println(slice.Join())
Output:

1,2,3

func (*IntSlice) Last

func (p *IntSlice) 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 := NewIntSliceV(1, 2, 3)
fmt.Println(slice.Last())
Output:

3

func (*IntSlice) LastN

func (p *IntSlice) LastN(n int) Slice

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

func (p *IntSlice) Len() int

Len returns the number of elements in this Slice

Example

Len --------------------------------------------------------------------------------------------------

fmt.Println(NewIntSliceV(1, 2, 3).Len())
Output:

3

func (*IntSlice) Less

func (p *IntSlice) Less(i, j int) bool

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

func (p *IntSlice) Nil() bool

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

func (p *IntSlice) Pair() (first, second *Object)

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

func (p *IntSlice) Pop() (elem *Object)

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

func (p *IntSlice) PopN(n int) (new Slice)

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

func (p *IntSlice) Prepend(elem interface{}) Slice

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) RefSlice

func (p *IntSlice) RefSlice() bool

RefSlice returns true if the underlying implementation is a RefSlice

func (*IntSlice) Reverse

func (p *IntSlice) Reverse() (new Slice)

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

func (p *IntSlice) ReverseM() Slice

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) S

func (p *IntSlice) S() (slice *StringSlice)

S is an alias to ToStringSlice

func (*IntSlice) SG

func (p *IntSlice) SG() (slice []string)

SG is an alias to ToStringSliceG

func (*IntSlice) Select

func (p *IntSlice) Select(sel func(O) bool) (new Slice)

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

func (p *IntSlice) Set(i int, elems interface{}) Slice

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

func (p *IntSlice) SetE(i int, elems interface{}) (Slice, 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 := NewIntSliceV(1, 2, 3)
fmt.Println(slice.SetE(0, 0))
Output:

[0 2 3] <nil>

func (*IntSlice) Shift

func (p *IntSlice) Shift() (elem *Object)

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

func (p *IntSlice) ShiftN(n int) (new Slice)

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

func (p *IntSlice) Single() bool

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

func (p *IntSlice) Slice(indices ...int) 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

func (p *IntSlice) Sort() (new Slice)

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

func (p *IntSlice) SortM() Slice

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

func (p *IntSlice) SortReverse() (new Slice)

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

func (p *IntSlice) SortReverseM() Slice

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

func (p *IntSlice) String() 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

func (p *IntSlice) Swap(i, j int)

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

func (p *IntSlice) Take(indices ...int) (new Slice)

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

func (p *IntSlice) 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 := NewIntSliceV(1, 2, 3)
fmt.Println(slice.TakeAt(1))
Output:

2

func (*IntSlice) TakeW

func (p *IntSlice) TakeW(sel func(O) bool) (new Slice)

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) 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) ToStringSliceG

func (p *IntSlice) ToStringSliceG() (slice []string)

ToStringSliceG converts the underlying slice into a []string slice

func (*IntSlice) Union

func (p *IntSlice) Union(slice interface{}) (new Slice)

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

func (p *IntSlice) UnionM(slice interface{}) Slice

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

func (p *IntSlice) Uniq() (new Slice)

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]

func (*IntSlice) UniqM

func (p *IntSlice) UniqM() Slice

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 := NewIntSliceV(1, 2, 3, 3)
fmt.Println(slice.UniqM())
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 (*InterSlice) A

func (p *InterSlice) A() string

A is an alias to String for brevity

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{}) Slice

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{}) Slice

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() Slice

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 Slice)

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{}) Slice

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 Slice)

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) Slice

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) Slice

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() Slice

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) Slice

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() Slice

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) Slice

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) Slice

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)) Slice

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) (Slice, 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)) Slice

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

func (p *InterSlice) EachIE(action func(int, O) error) (Slice, error)

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)) Slice

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) (Slice, 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)) Slice

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

func (p *InterSlice) EachRIE(action func(int, O) error) (Slice, error)

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) Slice

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{}) Slice

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) Slice

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) Nil

func (p *InterSlice) Nil() bool

Nil tests if this Slice is nil

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 Slice)

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{}) Slice

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 Slice)

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() Slice

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) S

func (p *InterSlice) S() (slice *StringSlice)

S is an alias to ToStringSlice

func (*InterSlice) SG

func (p *InterSlice) SG() (slice []string)

SG is an alias to ToStringSliceG

func (*InterSlice) Select

func (p *InterSlice) Select(sel func(O) bool) (new Slice)

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{}) Slice

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{}) (Slice, 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 Slice)

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) 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. 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 Slice)

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() Slice

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 Slice)

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() Slice

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 Slice)

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 Slice)

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) ToInterSlice

func (p *InterSlice) ToInterSlice() (slice []interface{})

ToInterSlice converts the given slice to a generic []interface{} slice

func (*InterSlice) ToStringSlice

func (p *InterSlice) ToStringSlice() (slice *StringSlice)

ToStringSlice converts the underlying slice into a *StringSlice

func (*InterSlice) ToStringSliceG

func (p *InterSlice) ToStringSliceG() (slice []string)

ToStringSliceG converts the underlying slice into a []string slice

func (*InterSlice) Union

func (p *InterSlice) Union(slice interface{}) (new Slice)

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{}) Slice

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 Slice)

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() Slice

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 Map

type Map 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() Map // 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 Map) // 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{}) Map          // 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) (Slice, 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) (Slice, 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) (Slice, 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) (Slice, 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.
	Inject(key string, val interface{}) Map                 // Inject sets the value for the given key location, using jq type selectors. Returns a reference to this Map.
	InjectE(key string, val interface{}) (m Map, err error) // InjectE 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() Slice                         // 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 Map, location ...string) Map // 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(key string) (val *Object)             // Query returns the value at the given key location, using jq type selectors. Returns empty *Object if not found.
	QueryE(key string) (val *Object, err error) // Query returns the value at the given key location, using jq type selectors. Returns empty *Object if not found.
	Remove(key string) Map                      // Remove modifies this map to remove the value at the given key location, using jq type selectors. Returns a reference to this Map
	RemoveE(key string) (m Map, err error)      // RemoveE modifies this map to remove the value at the given key 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(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.
	SetM(key, val interface{}) Map // SetM the value for the given key 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.
	WriteYaml(filename string) (err error) // WriteYaml converts the Map into a map[string]interface{} then calls sys.WriteYaml on it to write it out to disk.
}

Map provides a generic way to work with map types providing convenience methods on par with rapid development languages. 'this Map' refers to the current map instance being operated on. 'new Map' refers to a copy of the map.

func NewMap

func NewMap(obj interface{}) (new Map)

NewMap 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. Defaults to StringMap type if nothing is given.

Optimized: map[string]interface{}

Example

NewMap --------------------------------------------------------------------------------------------------

fmt.Println(NewMap(map[string]interface{}{"k": "v"}))
Output:

&map[k:v]

type MapSlice

type MapSlice []map[string]interface{}

MapSlice implements the Slice interface providing a generic way to work with slice types including convenience methods on par with rapid development languages.

func NewMapSlice

func NewMapSlice(slice interface{}) *MapSlice

NewMapSlice creates a new *MapSlice

Example
slice := NewMapSlice([]map[string]interface{}{{"foo": "bar"}})
fmt.Println(slice)
Output:

[&map[foo:bar]]

func NewMapSliceV

func NewMapSliceV(elems ...interface{}) *MapSlice

NewMapSliceV creates a new *MapSlice from the given variadic elements. Always returns at least a reference to an empty MapSlice.

Example (Empty)
slice := NewMapSliceV()
fmt.Println(slice)
Output:

[]
Example (Variadic)
slice := NewMapSliceV(map[string]interface{}{"foo1": "1"}, map[string]interface{}{"foo2": "2"})
fmt.Println(slice)
Output:

[&map[foo1:1] &map[foo2:2]]

func ToMapSlice

func ToMapSlice(obj interface{}) *MapSlice

ToMapSlice converts an interface to a MapSlice type.

func ToMapSliceE

func ToMapSliceE(obj interface{}) (val *MapSlice, err error)

ToMapSliceE converts an interface to a MapSlice type.

func (*MapSlice) A

func (p *MapSlice) A() string

A is an alias to String for brevity

func (*MapSlice) Any

func (p *MapSlice) 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.

func (*MapSlice) AnyS

func (p *MapSlice) AnyS(slice interface{}) bool

AnyS tests if this Slice contains any of the given Slice's elements. Incompatible types will return false. Supports MapSlice, *MapSlice, []string or *[]string

func (*MapSlice) AnyW

func (p *MapSlice) AnyW(sel func(O) bool) bool

AnyW tests if this Slice contains any that match the lambda selector.

func (*MapSlice) Append

func (p *MapSlice) Append(elem interface{}) Slice

Append an element to the end of this Slice and returns a reference to this Slice.

func (*MapSlice) AppendV

func (p *MapSlice) AppendV(elems ...interface{}) Slice

AppendV appends the variadic elements to the end of this Slice and returns a reference to this Slice.

func (*MapSlice) At

func (p *MapSlice) At(i int) (elem *Object)

At returns the element at the given index location. Allows for negative notation.

func (*MapSlice) Clear

func (p *MapSlice) Clear() Slice

Clear modifies this Slice to clear out all elements and returns a reference to this Slice.

func (*MapSlice) Concat

func (p *MapSlice) Concat(slice interface{}) (new Slice)

Concat returns a new Slice by appending the given Slice to this Slice using variadic expansion. Supports MapSlice, *MapSlice, []string or *[]string

func (*MapSlice) ConcatM

func (p *MapSlice) ConcatM(slice interface{}) Slice

ConcatM modifies this Slice by appending the given Slice using variadic expansion and returns a reference to this Slice. Supports MapSlice, *MapSlice, []string or *[]string

func (*MapSlice) Copy

func (p *MapSlice) Copy(indices ...int) (new Slice)

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.

func (*MapSlice) Count

func (p *MapSlice) Count(elem interface{}) (cnt int)

Count the number of elements in this Slice equal to the given element.

func (*MapSlice) CountW

func (p *MapSlice) CountW(sel func(O) bool) (cnt int)

CountW counts the number of elements in this Slice that match the lambda selector.

func (*MapSlice) Drop

func (p *MapSlice) Drop(indices ...int) Slice

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.

func (*MapSlice) DropAt

func (p *MapSlice) DropAt(i int) Slice

DropAt modifies this Slice to delete the element at the given index location. Allows for negative notation. Returns a reference to this Slice.

func (*MapSlice) DropFirst

func (p *MapSlice) DropFirst() Slice

DropFirst modifies this Slice to delete the first element and returns a reference to this Slice.

func (*MapSlice) DropFirstN

func (p *MapSlice) DropFirstN(n int) Slice

DropFirstN modifies this Slice to delete the first n elements and returns a reference to this Slice.

func (*MapSlice) DropLast

func (p *MapSlice) DropLast() Slice

DropLast modifies this Slice to delete the last element and returns a reference to this Slice.

func (*MapSlice) DropLastN

func (p *MapSlice) DropLastN(n int) Slice

DropLastN modifies thi Slice to delete the last n elements and returns a reference to this Slice.

func (*MapSlice) DropW

func (p *MapSlice) DropW(sel func(O) bool) Slice

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 (*MapSlice) Each

func (p *MapSlice) Each(action func(O)) Slice

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
NewMapSliceV([]map[string]interface{}{{"foo": "bar"}}).Each(func(x O) {
	fmt.Printf("%v", x)
})
Output:

map[foo:bar]

func (*MapSlice) EachE

func (p *MapSlice) EachE(action func(O) error) (Slice, 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
NewMapSliceV([]map[string]interface{}{{"foo": "bar"}}).EachE(func(x O) error {
	fmt.Printf("%v", x)
	return nil
})
Output:

map[foo:bar]

func (*MapSlice) EachI

func (p *MapSlice) EachI(action func(int, O)) Slice

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

func (*MapSlice) EachIE

func (p *MapSlice) EachIE(action func(int, O) error) (Slice, error)

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 (*MapSlice) EachR

func (p *MapSlice) EachR(action func(O)) Slice

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 (*MapSlice) EachRE

func (p *MapSlice) EachRE(action func(O) error) (Slice, 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 (*MapSlice) EachRI

func (p *MapSlice) EachRI(action func(int, O)) Slice

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 (*MapSlice) EachRIE

func (p *MapSlice) EachRIE(action func(int, O) error) (Slice, error)

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 (*MapSlice) Empty

func (p *MapSlice) Empty() bool

Empty tests if this Slice is empty.

func (*MapSlice) First

func (p *MapSlice) 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 (*MapSlice) FirstN

func (p *MapSlice) FirstN(n int) Slice

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 (*MapSlice) G

func (p *MapSlice) G() []map[string]interface{}

G returns the underlying data structure as a builtin Go type

func (*MapSlice) Index

func (p *MapSlice) 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 (*MapSlice) Insert

func (p *MapSlice) Insert(i int, obj interface{}) Slice

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 (*MapSlice) InterSlice

func (p *MapSlice) InterSlice() bool

InterSlice returns true if the underlying implementation is a RefSlice

func (*MapSlice) Join

func (p *MapSlice) 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 (*MapSlice) Last

func (p *MapSlice) 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 (*MapSlice) LastN

func (p *MapSlice) LastN(n int) Slice

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 (*MapSlice) Len

func (p *MapSlice) Len() int

Len returns the number of elements in this Slice

func (*MapSlice) Less

func (p *MapSlice) Less(i, j int) bool

Less returns true if the element indexed by i is less than the element indexed by j.

func (*MapSlice) Nil

func (p *MapSlice) Nil() bool

Nil tests if this Slice is nil

func (*MapSlice) O

func (p *MapSlice) O() interface{}

O returns the underlying data structure as is

func (*MapSlice) Pair

func (p *MapSlice) Pair() (first, second *Object)

Pair simply returns the first and second Slice elements as Objects

func (*MapSlice) Pop

func (p *MapSlice) Pop() (elem *Object)

Pop modifies this Slice to remove the last element and returns the removed element as an Object.

func (*MapSlice) PopN

func (p *MapSlice) PopN(n int) (new Slice)

PopN modifies this Slice to remove the last n elements and returns the removed elements as a new Slice.

func (*MapSlice) Prepend

func (p *MapSlice) Prepend(elem interface{}) Slice

Prepend modifies this Slice to add the given element at the begining and returns a reference to this Slice.

func (*MapSlice) RefSlice

func (p *MapSlice) RefSlice() bool

RefSlice returns true if the underlying implementation is a RefSlice

func (*MapSlice) Reverse

func (p *MapSlice) Reverse() (new Slice)

Reverse returns a new Slice with the order of the elements reversed.

func (*MapSlice) ReverseM

func (p *MapSlice) ReverseM() Slice

ReverseM modifies this Slice reversing the order of the elements and returns a reference to this Slice.

func (*MapSlice) S

func (p *MapSlice) S() (slice *StringSlice)

S is an alias to ToStringSlice

func (*MapSlice) SG

func (p *MapSlice) SG() (slice []string)

SG is an alias to ToStringSliceG

func (*MapSlice) Select

func (p *MapSlice) Select(sel func(O) bool) (new Slice)

Select creates a new slice with the elements that match the lambda selector.

func (*MapSlice) Set

func (p *MapSlice) Set(i int, elem interface{}) Slice

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.

func (*MapSlice) SetE

func (p *MapSlice) SetE(i int, elems interface{}) (Slice, 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.

func (*MapSlice) Shift

func (p *MapSlice) Shift() (elem *Object)

Shift modifies this Slice to remove the first element and returns the removed element as an Object.

func (*MapSlice) ShiftN

func (p *MapSlice) ShiftN(n int) (new Slice)

ShiftN modifies this Slice to remove the first n elements and returns the removed elements as a new Slice.

func (*MapSlice) Single

func (p *MapSlice) Single() bool

Single reports true if there is only one element in this Slice.

func (*MapSlice) Slice

func (p *MapSlice) Slice(indices ...int) 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. NewMapSliceV(1,2,3).Slice(0, -1) == [1,2,3] && NewMapSliceV(1,2,3).Slice(1,2) == [2,3]

func (*MapSlice) Sort

func (p *MapSlice) Sort() (new Slice)

Sort returns a new Slice with sorted elements.

func (*MapSlice) SortM

func (p *MapSlice) SortM() Slice

SortM modifies this Slice sorting the elements and returns a reference to this Slice.

func (*MapSlice) SortReverse

func (p *MapSlice) SortReverse() (new Slice)

SortReverse returns a new Slice sorting the elements in reverse.

func (*MapSlice) SortReverseM

func (p *MapSlice) SortReverseM() Slice

SortReverseM modifies this Slice sorting the elements in reverse and returns a reference to this Slice.

func (*MapSlice) String

func (p *MapSlice) String() string

String returns a string representation of this Slice, implements the Stringer interface

func (*MapSlice) Swap

func (p *MapSlice) Swap(i, j int)

Swap modifies this Slice swapping the indicated elements.

func (*MapSlice) Take

func (p *MapSlice) Take(indices ...int) (new Slice)

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 (*MapSlice) TakeAt

func (p *MapSlice) 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 (*MapSlice) TakeW

func (p *MapSlice) TakeW(sel func(O) bool) (new Slice)

TakeW modifies this Slice removing the elements that match the lambda selector and returns them as a new Slice.

func (*MapSlice) ToInterSlice

func (p *MapSlice) ToInterSlice() (slice []interface{})

ToInterSlice converts the given slice to a generic []interface{} slice

func (*MapSlice) ToStringSlice

func (p *MapSlice) ToStringSlice() (slice *StringSlice)

ToStringSlice converts the underlying slice into a *StringSlice

func (*MapSlice) ToStringSliceG

func (p *MapSlice) ToStringSliceG() (slice []string)

ToStringSliceG converts the underlying slice into a []string slice

func (*MapSlice) Union

func (p *MapSlice) Union(slice interface{}) (new Slice)

Union returns a new Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports MapSlice, *MapSlice, []string or *[]string

func (*MapSlice) UnionM

func (p *MapSlice) UnionM(slice interface{}) Slice

UnionM modifies this Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports MapSlice, *MapSlice, []string or *[]string

func (*MapSlice) Uniq

func (p *MapSlice) Uniq() (new Slice)

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 (*MapSlice) UniqM

func (p *MapSlice) UniqM() Slice

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 O

type O interface{}

O is an alias for interface{} used in lambda expresssions for brevity.

type Object

type Object struct {
	// contains filtered or unexported fields
}

Object is a wrapper around an interface{} value wproviding 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) A

func (p *Object) A() string

A is an alias to String for brevity

func (*Object) C

func (p *Object) C() *Char

C is an alias to ToChar for brevity

func (*Object) M

func (p *Object) M() *StringMap

M is an alias to ToStringMap

func (*Object) MG

func (p *Object) MG() map[string]interface{}

MG is an alias to ToStringMapG

func (*Object) Nil

func (p *Object) Nil() bool

Nil tests if the numerable is nil

func (*Object) O

func (p *Object) O() interface{}

O returns the underlying data structure as is

func (*Object) Query

func (p *Object) Query(key string) *Object

Query an object if it is a StringMap type

func (*Object) QueryE

func (p *Object) QueryE(key string) (obj *Object, err error)

QueryE an object if it is a StringMap type

func (*Object) R

func (p *Object) R() rune

R is an alias to ToRune for brevity

func (*Object) S

func (p *Object) S() *StringSlice

S is an alias to ToStringSlice for brevity

func (*Object) SG

func (p *Object) SG() []string

SG is an alias to ToStringSliceG for brevity

func (*Object) String

func (p *Object) String() string

String returns a string representation of the Object, implements Stringer interface.

func (*Object) ToBool

func (p *Object) ToBool() bool

ToBool casts an interface to a bool type.

func (*Object) ToBoolE

func (p *Object) ToBoolE() (bool, error)

ToBoolE casts an interface to a bool type.

func (*Object) ToBoolSlice

func (p *Object) ToBoolSlice() []bool

ToBoolSlice casts an interface to a []bool type.

func (*Object) ToBoolSliceE

func (p *Object) ToBoolSliceE() ([]bool, error)

ToBoolSliceE casts an interface to a []bool type.

func (*Object) ToChar

func (p *Object) ToChar() *Char

ToChar casts an interface to a *Char type.

func (*Object) ToDuration

func (p *Object) ToDuration() time.Duration

ToDuration casts an interface to a time.Duration type.

func (*Object) ToDurationE

func (p *Object) ToDurationE() (time.Duration, error)

ToDurationE casts an interface to a time.Duration type.

func (*Object) ToDurationSlice

func (p *Object) ToDurationSlice() []time.Duration

ToDurationSlice casts an interface to a []time.Duration type.

func (*Object) ToDurationSliceE

func (p *Object) ToDurationSliceE() ([]time.Duration, error)

ToDurationSliceE casts an interface to a []time.Duration type.

func (*Object) ToFloat32

func (p *Object) ToFloat32() float32

ToFloat32 casts an interface to a float32 type.

func (*Object) ToFloat32E

func (p *Object) ToFloat32E() (float32, error)

ToFloat32E casts an interface to a float32 type.

func (*Object) ToFloat64

func (p *Object) ToFloat64() float64

ToFloat64 converts an interface to a float64 type.

func (*Object) ToFloat64E

func (p *Object) ToFloat64E() (float64, error)

ToFloat64E converts an interface to a float64 type.

func (*Object) ToInt

func (p *Object) ToInt() int

ToInt casts an interface to an int type.

func (*Object) ToInt16

func (p *Object) ToInt16() int16

ToInt16 casts an interface to an int16 type.

func (*Object) ToInt16E

func (p *Object) ToInt16E() (int16, error)

ToInt16E casts an interface to an int16 type.

func (*Object) ToInt32

func (p *Object) ToInt32() int32

ToInt32 casts an interface to an int32 type.

func (*Object) ToInt32E

func (p *Object) ToInt32E() (int32, error)

ToInt32E casts an interface to an int32 type.

func (*Object) ToInt64

func (p *Object) ToInt64() int64

ToInt64 casts an interface to an int64 type.

func (*Object) ToInt64E

func (p *Object) ToInt64E() (int64, error)

ToInt64E casts an interface to an int64 type.

func (*Object) ToInt8

func (p *Object) ToInt8() int8

ToInt8 casts an interface to an int8 type.

func (*Object) ToInt8E

func (p *Object) ToInt8E() (int8, error)

ToInt8E casts an interface to an int8 type.

func (*Object) ToIntE

func (p *Object) ToIntE() (int, error)

ToIntE casts an interface to an int type.

func (*Object) ToIntSlice

func (p *Object) ToIntSlice() *IntSlice

ToIntSlice converts an interface to a *IntSlice type.

func (*Object) ToIntSliceE

func (p *Object) ToIntSliceE() (*IntSlice, error)

ToIntSliceE converts an interface to a *IntSlice type.

func (*Object) ToIntSliceG

func (p *Object) ToIntSliceG() []int

ToIntSliceG converts an interface to a []int type.

func (*Object) ToIntSliceGE

func (p *Object) ToIntSliceGE() ([]int, error)

ToIntSliceGE converts an interface to a []int type.

func (*Object) ToMapSlice

func (p *Object) ToMapSlice() *MapSlice

ToMapSlice converts an interface to a *MapSlice type.

func (*Object) ToMapSliceE

func (p *Object) ToMapSliceE() (*MapSlice, error)

ToMapSliceE converts an interface to a *MapSlice type.

func (*Object) ToMapSliceG

func (p *Object) ToMapSliceG() []map[string]interface{}

ToMapSliceG converts an interface to a []map[string]interface{} type.

func (*Object) ToMapSliceGE

func (p *Object) ToMapSliceGE() ([]map[string]interface{}, error)

ToMapSliceGE converts an interface to a []map[string]interface{} type.

func (*Object) ToRune

func (p *Object) ToRune() rune

ToRune casts an interface to a rune type.

func (*Object) ToSlice

func (p *Object) ToSlice() []interface{}

ToSlice casts an interface to a []interface{} type.

func (*Object) ToSliceE

func (p *Object) ToSliceE() ([]interface{}, error)

ToSliceE casts an interface to a []interface{} type.

func (*Object) ToStr

func (p *Object) ToStr() *Str

ToStr converts object into a *Str

func (*Object) ToString

func (p *Object) ToString() string

ToString casts an interface to a string type.

func (*Object) ToStringE

func (p *Object) ToStringE() (string, error)

ToStringE casts an interface to a string type.

func (*Object) ToStringMap

func (p *Object) ToStringMap() *StringMap

ToStringMap converts an interface to a *StringMap type.

func (*Object) ToStringMapBool

func (p *Object) ToStringMapBool() map[string]bool

ToStringMapBool casts an interface to a map[string]bool type.

func (*Object) ToStringMapBoolE

func (p *Object) ToStringMapBoolE() (map[string]bool, error)

ToStringMapBoolE casts an interface to a map[string]bool type.

func (*Object) ToStringMapE

func (p *Object) ToStringMapE() (*StringMap, error)

ToStringMapE converts an interface to a *StringMap type.

func (*Object) ToStringMapG

func (p *Object) ToStringMapG() map[string]interface{}

ToStringMapG converts an interface to a map[string]interface{} type.

func (*Object) ToStringMapGE

func (p *Object) ToStringMapGE() (map[string]interface{}, error)

ToStringMapGE converts an interface to a map[string]interface{} type.

func (*Object) ToStringMapInt

func (p *Object) ToStringMapInt() map[string]int

ToStringMapInt casts an interface to a map[string]int type.

func (*Object) ToStringMapInt64

func (p *Object) ToStringMapInt64() map[string]int64

ToStringMapInt64 casts an interface to a map[string]int64 type.

func (*Object) ToStringMapInt64E

func (p *Object) ToStringMapInt64E() (map[string]int64, error)

ToStringMapInt64E casts an interface to a map[string]int64 type.

func (*Object) ToStringMapIntE

func (p *Object) ToStringMapIntE() (map[string]int, error)

ToStringMapIntE casts an interface to a map[string]int type.

func (*Object) ToStringMapString

func (p *Object) ToStringMapString() map[string]string

ToStringMapString casts an interface to a map[string]string type.

func (*Object) ToStringMapStringE

func (p *Object) ToStringMapStringE() (map[string]string, error)

ToStringMapStringE casts an interface to a map[string]string type.

func (*Object) ToStringMapStringSlice

func (p *Object) ToStringMapStringSlice() map[string][]string

ToStringMapStringSlice casts an interface to a map[string][]string type.

func (*Object) ToStringMapStringSliceE

func (p *Object) ToStringMapStringSliceE() (map[string][]string, error)

ToStringMapStringSliceE casts an interface to a map[string][]string 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.

func (*Object) ToStringSliceG

func (p *Object) ToStringSliceG() []string

ToStringSliceG casts an interface to a []string type.

func (*Object) ToStringSliceGE

func (p *Object) ToStringSliceGE() ([]string, error)

ToStringSliceGE casts an interface to a []string type.

func (*Object) ToTime

func (p *Object) ToTime() time.Time

ToTime casts an interface to a time.Time type.

func (*Object) ToTimeE

func (p *Object) ToTimeE() (time.Time, error)

ToTimeE casts an interface to a time.Time type.

func (*Object) ToUint

func (p *Object) ToUint() uint

ToUint casts an interface to a uint type.

func (*Object) ToUint16

func (p *Object) ToUint16() uint16

ToUint16 casts an interface to a uint16 type.

func (*Object) ToUint16E

func (p *Object) ToUint16E() (uint16, error)

ToUint16E casts an interface to a uint16 type.

func (*Object) ToUint32

func (p *Object) ToUint32() uint32

ToUint32 casts an interface to a uint32 type.

func (*Object) ToUint32E

func (p *Object) ToUint32E() (uint32, error)

ToUint32E casts an interface to a uint32 type.

func (*Object) ToUint64

func (p *Object) ToUint64() uint64

ToUint64 casts an interface to a uint64 type.

func (*Object) ToUint64E

func (p *Object) ToUint64E() (uint64, error)

ToUint64E casts an interface to a uint64 type.

func (*Object) ToUint8

func (p *Object) ToUint8() uint8

ToUint8 casts an interface to a uint8 type.

func (*Object) ToUint8E

func (p *Object) ToUint8E() (uint8, error)

ToUint8E casts an interface to a uint8 type.

func (*Object) ToUintE

func (p *Object) ToUintE() (uint, error)

ToUintE casts an interface to a uint 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) A

func (p *RefSlice) A() string

A is an alias to String for brevity

func (*RefSlice) Any

func (p *RefSlice) 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 := 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

func (p *RefSlice) AnyS(slice interface{}) bool

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

func (p *RefSlice) AnyW(sel func(O) bool) bool

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

func (p *RefSlice) Append(elem interface{}) Slice

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

func (p *RefSlice) AppendV(elems ...interface{}) Slice

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

func (p *RefSlice) At(i int) (elem *Object)

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

func (p *RefSlice) Clear() Slice

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

func (p *RefSlice) Concat(slice interface{}) (new Slice)

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

func (p *RefSlice) ConcatM(slice interface{}) Slice

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

func (p *RefSlice) Copy(indices ...int) (new Slice)

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

func (p *RefSlice) Count(elem interface{}) (cnt int)

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

func (p *RefSlice) CountW(sel func(O) bool) (cnt int)

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

func (p *RefSlice) Drop(indices ...int) Slice

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

func (p *RefSlice) DropAt(i int) Slice

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

func (p *RefSlice) DropFirst() Slice

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

func (p *RefSlice) DropFirstN(n int) Slice

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

func (p *RefSlice) DropLast() Slice

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

func (p *RefSlice) DropLastN(n int) Slice

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

func (p *RefSlice) DropW(sel func(O) bool) Slice

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

func (p *RefSlice) Each(action func(O)) Slice

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

func (p *RefSlice) EachE(action func(O) error) (Slice, 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
NewRefSliceV(1, 2, 3).EachE(func(x O) error {
	fmt.Printf("%v", x)
	return nil
})
Output:

123

func (*RefSlice) EachI

func (p *RefSlice) EachI(action func(int, O)) Slice

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

func (p *RefSlice) EachIE(action func(int, O) error) (Slice, error)

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

func (p *RefSlice) EachR(action func(O)) Slice

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

func (p *RefSlice) EachRE(action func(O) error) (Slice, 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
NewRefSliceV(1, 2, 3).EachRE(func(x O) error {
	fmt.Printf("%v", x)
	return nil
})
Output:

321

func (*RefSlice) EachRI

func (p *RefSlice) EachRI(action func(int, O)) Slice

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

func (p *RefSlice) EachRIE(action func(int, O) error) (Slice, error)

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

func (p *RefSlice) Empty() bool

Empty tests if this Slice is empty.

Example

Empty --------------------------------------------------------------------------------------------------

fmt.Println(NewRefSliceV().Empty())
Output:

true

func (*RefSlice) First

func (p *RefSlice) 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 := NewRefSliceV(1, 2, 3)
fmt.Println(slice.First().O())
Output:

1

func (*RefSlice) FirstN

func (p *RefSlice) FirstN(n int) Slice

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

func (p *RefSlice) 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 := NewRefSliceV(1, 2, 3)
fmt.Println(slice.Index(2))
Output:

1

func (*RefSlice) Insert

func (p *RefSlice) Insert(i int, elem interface{}) Slice

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

func (p *RefSlice) InsertS(i int, slice interface{}) Slice

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

func (p *RefSlice) InterSlice() bool

InterSlice returns true if the underlying implementation is a RefSlice

func (*RefSlice) Join

func (p *RefSlice) 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 := NewRefSliceV(1, 2, 3)
fmt.Println(slice.Join())
Output:

1,2,3

func (*RefSlice) Last

func (p *RefSlice) 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 := NewRefSliceV(1, 2, 3)
fmt.Println(slice.Last())
Output:

3

func (*RefSlice) LastN

func (p *RefSlice) LastN(n int) Slice

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) Len

func (p *RefSlice) Len() int

Len returns the number of elements in this Slice

func (*RefSlice) Less

func (p *RefSlice) 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
slice := NewRefSliceV(2, 3, 1)
fmt.Println(slice.Sort().O())
Output:

[1 2 3]

func (*RefSlice) Nil

func (p *RefSlice) Nil() bool

Nil tests if this Slice is nil

func (*RefSlice) O

func (p *RefSlice) O() interface{}

O returns the underlying data structure as is

func (*RefSlice) Pair

func (p *RefSlice) Pair() (first, second *Object)

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

func (p *RefSlice) Pop() (elem *Object)

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

func (p *RefSlice) PopN(n int) (new Slice)

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

func (p *RefSlice) Prepend(elem interface{}) Slice

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

func (p *RefSlice) RefSlice() bool

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

func (p *RefSlice) Reverse() (new Slice)

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

func (p *RefSlice) ReverseM() Slice

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) S

func (p *RefSlice) S() (slice *StringSlice)

S is an alias to ToStringSlice

func (*RefSlice) SG

func (p *RefSlice) SG() (slice []string)

SG is an alias to ToStringSliceG

func (*RefSlice) Select

func (p *RefSlice) Select(sel func(O) bool) (new Slice)

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

func (p *RefSlice) Set(i int, elem interface{}) Slice

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

func (p *RefSlice) SetE(i int, elem interface{}) (Slice, 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
slice := NewRefSliceV(1, 2, 3)
fmt.Println(slice.SetE(0, 0))
Output:

[0 2 3] <nil>

func (*RefSlice) Shift

func (p *RefSlice) Shift() (elem *Object)

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

func (p *RefSlice) ShiftN(n int) (new Slice)

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

func (p *RefSlice) Single() bool

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

func (p *RefSlice) Slice(indices ...int) 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

func (p *RefSlice) Sort() (new Slice)

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

func (p *RefSlice) SortM() Slice

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

func (p *RefSlice) SortReverse() (new Slice)

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

func (p *RefSlice) SortReverseM() Slice

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

func (p *RefSlice) String() 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

func (p *RefSlice) Swap(i, j int)

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

func (p *RefSlice) Take(indices ...int) (new Slice)

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

func (p *RefSlice) 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 := NewRefSliceV(1, 2, 3)
fmt.Println(slice.TakeAt(2).O())
Output:

3

func (*RefSlice) TakeW

func (p *RefSlice) TakeW(sel func(O) bool) (new Slice)

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) 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) ToStringSliceG

func (p *RefSlice) ToStringSliceG() (slice []string)

ToStringSliceG converts the underlying slice into a []string slice

func (*RefSlice) Union

func (p *RefSlice) Union(slice interface{}) (new Slice)

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

func (p *RefSlice) UnionM(slice interface{}) Slice

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

func (p *RefSlice) Uniq() (new Slice)

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]

func (*RefSlice) UniqM

func (p *RefSlice) UniqM() Slice

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 := NewRefSliceV(1, 2, 3, 3)
fmt.Println(slice.UniqM())
Output:

[1 2 3]

type RuneMapBool

type RuneMapBool map[rune]bool

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 Slice added in v1.1.9

type Slice interface {
	A() string                                        // A is an alias to String for brevity
	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{}) Slice                    // Append an element to the end of this Slice and returns a reference to this Slice.
	AppendV(elems ...interface{}) Slice               // 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() Slice                                     // Clear modifies this Slice to clear out all elements and returns a reference to this Slice.
	Concat(slice interface{}) (new Slice)             // Concat returns a new Slice by appending the given Slice to this Slice using variadic expansion.
	ConcatM(slice interface{}) Slice                  // ConcatM modifies this Slice by appending the given Slice using variadic expansion and returns a reference to this Slice.
	Copy(indices ...int) (new Slice)                  // 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) Slice                        // Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice.
	DropAt(i int) Slice                               // DropAt modifies this Slice to delete the element at the given index location. Allows for negative notation.
	DropFirst() Slice                                 // DropFirst modifies this Slice to delete the first element and returns a reference to this Slice.
	DropFirstN(n int) Slice                           // DropFirstN modifies this Slice to delete the first n elements and returns a reference to this Slice.
	DropLast() Slice                                  // DropLast modifies this Slice to delete the last element and returns a reference to this Slice.
	DropLastN(n int) Slice                            // DropLastN modifies thi Slice to delete the last n elements and returns a reference to this Slice.
	DropW(sel func(O) bool) Slice                     // DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice.
	Each(action func(O)) Slice                        // Each calls the given lambda once for each element in this Slice, passing in that element
	EachE(action func(O) error) (Slice, error)        // EachE calls the given lambda once for each element in this Slice, passing in that element
	EachI(action func(int, O)) Slice                  // EachI calls the given lambda once for each element in this Slice, passing in the index and element
	EachIE(action func(int, O) error) (Slice, error)  // EachIE calls the given lambda once for each element in this Slice, passing in the index and element
	EachR(action func(O)) Slice                       // EachR calls the given lambda once for each element in this Slice in reverse, passing in that element
	EachRE(action func(O) error) (Slice, error)       // EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element
	EachRI(action func(int, O)) Slice                 // EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element
	EachRIE(action func(int, O) error) (Slice, 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) Slice                               // 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{}) Slice             // 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) Slice                                // 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.
	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 Slice)                           // PopN modifies this Slice to remove the last n elements and returns the removed elements as a new Slice.
	Prepend(elem interface{}) Slice                   // 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 Slice)                             // Reverse returns a new Slice with the order of the elements reversed.
	ReverseM() Slice                                  // 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
	SG() (slice []string)                             // S is an alias to ToStringSliceG
	Select(sel func(O) bool) (new Slice)              // Select creates a new slice with the elements that match the lambda selector.
	Set(i int, elems interface{}) Slice               // Set the element(s) at the given index location to the given element(s). Allows for negative notation.
	SetE(i int, elems interface{}) (Slice, 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 Slice)                         // 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) Slice                       // Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation.
	Sort() (new Slice)                                // Sort returns a new Slice with sorted elements.
	SortM() Slice                                     // SortM modifies this Slice sorting the elements and returns a reference to this Slice.
	SortReverse() (new Slice)                         // SortReverse returns a new Slice sorting the elements in reverse.
	SortReverseM() Slice                              // 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 Slice)                  // 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 Slice)               // TakeW modifies this Slice removing the elements that match the lambda selector and returns them as a new Slice.
	ToInterSlice() (slice []interface{})              // ToInterSlice converts the given slice to a generic []interface{} slice
	ToStringSlice() (slice *StringSlice)              // ToStringSlice converts the underlying slice into a *StringSlice
	ToStringSliceG() (slice []string)                 // ToStringSliceG converts the underlying slice into a []string slice
	Union(slice interface{}) (new Slice)              // 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{}) Slice                   // UnionM modifies this Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order.
	Uniq() (new Slice)                                // Uniq returns a new Slice with all non uniq elements removed while preserving element order.
	UniqM() Slice                                     // UniqM modifies this Slice to remove all non uniq elements while preserving element order.
}

Slice 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 NewSlice

func NewSlice(obj interface{}) (new Slice)

NewSlice 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

func NewSliceV

func NewSliceV(elems ...interface{}) (new Slice)

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

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) A

func (p *Str) A() string

A exports the Str as a Go string

func (*Str) All

func (p *Str) All(elems ...interface{}) bool

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

func (p *Str) AllS(slice interface{}) bool

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

func (p *Str) 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: 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

func (p *Str) AnyS(slice interface{}) bool

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

func (p *Str) AnyW(sel func(O) bool) bool

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

func (p *Str) Append(elem interface{}) Slice

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

func (p *Str) AppendV(elems ...interface{}) Slice

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

func (p *Str) Ascii() *Str

Ascii converts the string to pure ASCII

Example

Ascii --------------------------------------------------------------------------------------------------

fmt.Println(A("2�gspu�data").Ascii().A())
Output:

2 gspu data

func (*Str) AsciiA

func (p *Str) AsciiA() string

AsciiA converts the string to pure ASCII

Example

AsciiA --------------------------------------------------------------------------------------------------

fmt.Println(A("2�gspu�data").AsciiA())
Output:

2 gspu data

func (*Str) AsciiOnly

func (p *Str) AsciiOnly() bool

AsciiOnly checks to see if this is an ASCII only string

Example

AsciiOnly --------------------------------------------------------------------------------------------------

fmt.Println(A("foo").AsciiOnly())
Output:

true

func (*Str) At

func (p *Str) At(i int) (elem *Object)

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

func (p *Str) B() []byte

B exports the Str as a Go []byte

Example

B --------------------------------------------------------------------------------------------------

fmt.Println(A("foobar").B())
Output:

[102 111 111 98 97 114]

func (*Str) C

func (p *Str) C() *Char

C exports the Str as a Char

func (*Str) Clear

func (p *Str) Clear() Slice

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())

func (*Str) Concat

func (p *Str) Concat(slice interface{}) (new Slice)

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) ConcatA

func (p *Str) ConcatA(str interface{}) string

ConcatA calls Concat and returns it as a string for brevity

func (*Str) ConcatM

func (p *Str) ConcatM(slice interface{}) Slice

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

func (p *Str) Contains(str string) bool

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

func (p *Str) ContainsAny(chars string) bool

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

func (p *Str) ContainsRune(r rune) bool

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

func (p *Str) Copy(indices ...int) (new Slice)

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) CopyA

func (p *Str) CopyA(indices ...int) (new string)

CopyA calls Copy and returns it as a string for brevity

func (*Str) Count

func (p *Str) Count(elem interface{}) (cnt int)

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

func (p *Str) CountW(sel func(O) bool) (cnt int)

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

func (p *Str) Drop(indices ...int) Slice

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

func (p *Str) DropAt(i int) Slice

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

func (p *Str) DropFirst() Slice

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

func (p *Str) DropFirstN(n int) Slice

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

func (p *Str) DropLast() Slice

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

func (p *Str) DropLastN(n int) Slice

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

func (p *Str) DropW(sel func(O) bool) Slice

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

func (p *Str) Each(action func(O)) Slice

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

func (p *Str) EachE(action func(O) error) (Slice, error)

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

func (p *Str) EachI(action func(int, O)) Slice

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

func (p *Str) EachIE(action func(int, O) error) (Slice, error)

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

func (p *Str) EachR(action func(O)) Slice

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

func (p *Str) EachRE(action func(O) error) (Slice, error)

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

func (p *Str) EachRI(action func(int, O)) Slice

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

func (p *Str) EachRIE(action func(int, O) error) (Slice, error)

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

func (p *Str) Empty() bool

Empty tests if this Slice is empty.

Example

Empty --------------------------------------------------------------------------------------------------

fmt.Println(NewStrV().Empty())
Output:

true

func (*Str) Equal

func (p *Str) Equal(val interface{}) bool

Equal tests if this Str is equal to the given string

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

func (p *Str) 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 := NewStrV("1", "2", "3")
fmt.Println(slice.First())
Output:

1

func (*Str) FirstN

func (p *Str) FirstN(n int) Slice

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

func (p *Str) G() string

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

func (p *Str) HasAnyPrefix(prefixes interface{}) bool

HasAnyPrefix checks if the string has any of the given prefixes

Example
fmt.Println(NewStr("foobar").HasAnyPrefix("foo"))
Output:

true

func (*Str) HasAnyPrefixV

func (p *Str) HasAnyPrefixV(prefixes ...interface{}) bool

HasAnyPrefixV checks if the string has any of the given prefixes

Example
fmt.Println(NewStr("foobar").HasAnyPrefixV("bar", "foo"))
Output:

true

func (*Str) HasAnySuffix

func (p *Str) HasAnySuffix(prefixes interface{}) bool

HasAnySuffix checks if the string has any of the given prefixes

Example
fmt.Println(NewStr("foobar").HasAnySuffix("bar"))
Output:

true

func (*Str) HasAnySuffixV

func (p *Str) HasAnySuffixV(prefixes ...interface{}) bool

HasAnySuffixV checks if the string has any of the given prefixes

Example
fmt.Println(NewStr("foobar").HasAnySuffixV("bar", "foo"))
Output:

true

func (*Str) HasPrefix

func (p *Str) HasPrefix(prefix interface{}) bool

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

func (p *Str) HasSuffix(prefix interface{}) bool

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

func (p *Str) Index(substr interface{}) (loc int)

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

func (p *Str) IndexAny(elems interface{}) (loc int)

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

func (p *Str) IndexChar(char interface{}) (loc int)

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

func (p *Str) Insert(i int, obj interface{}) Slice

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

func (p *Str) InterSlice() bool

InterSlice returns true if the underlying implementation is a RefSlice

func (*Str) Join

func (p *Str) 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 := NewStrV("1", "2", "3")
fmt.Println(slice.Join())
Output:

1,2,3

func (*Str) Last

func (p *Str) 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 := NewStrV("1", "2", "3")
fmt.Println(slice.Last())
Output:

3

func (*Str) LastIndex

func (p *Str) LastIndex(substr interface{}) (loc int)

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

func (p *Str) LastIndexAny(elems interface{}) (loc int)

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

func (p *Str) LastIndexChar(char interface{}) (loc int)

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

func (p *Str) LastN(n int) Slice

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

func (p *Str) Len() int

Len returns the number of elements in this Slice

Example

Len --------------------------------------------------------------------------------------------------

fmt.Println(NewStrV("1", "2", "3").Len())
Output:

3

func (*Str) Less

func (p *Str) Less(i, j int) bool

Less returns true if the element indexed by i is less than the element indexed by j.

Example
slice := NewStrV("2", "3", "1")
fmt.Println(slice.Less(0, 2))
Output:

false

func (*Str) Nil

func (p *Str) Nil() bool

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

func (p *Str) Pair() (first, second *Object)

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

func (p *Str) Pop() (elem *Object)

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

func (p *Str) PopN(n int) (new Slice)

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

func (p *Str) Prepend(elem interface{}) Slice

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) RefSlice

func (p *Str) RefSlice() bool

RefSlice returns true if the underlying implementation is a RefSlice

func (*Str) Replace

func (p *Str) Replace(old, new interface{}, n int) *Str

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

func (p *Str) ReplaceAll(old, new interface{}) *Str

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

func (p *Str) Reverse() (new Slice)

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

func (p *Str) ReverseM() Slice

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) S

func (p *Str) S() (slice *StringSlice)

S is an alias to ToStringSlice

func (*Str) SG

func (p *Str) SG() (slice []string)

SG is an alias to ToStringSliceG

func (*Str) Select

func (p *Str) Select(sel func(O) bool) (new Slice)

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

func (p *Str) Set(i int, elem interface{}) Slice

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

func (p *Str) SetE(i int, elems interface{}) (Slice, error)

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

func (p *Str) Shift() (elem *Object)

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

func (p *Str) ShiftN(n int) (new Slice)

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

func (p *Str) Single() bool

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

func (p *Str) Slice(indices ...int) 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

func (p *Str) Sort() (new Slice)

Sort returns a new Slice with sorted elements.

Example
slice := NewStrV("2", "3", "1")
fmt.Println(slice.Sort())
Output:

123

func (*Str) SortM

func (p *Str) SortM() Slice

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

func (p *Str) SortReverse() (new Slice)

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

func (p *Str) SortReverseM() Slice

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 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.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) SplitQuotes

func (p *Str) SplitQuotes(separator ...string) (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

func (p *Str) String() 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

func (p *Str) Swap(i, j int)

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

func (p *Str) Take(indices ...int) (new Slice)

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

func (p *Str) 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 := NewStrV("1", "2", "3")
fmt.Println(slice.TakeAt(1))
Output:

2

func (*Str) TakeW

func (p *Str) TakeW(sel func(O) bool) (new Slice)

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

func (p *Str) Title() (new *Str)

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) ToInterSlice

func (p *Str) ToInterSlice() (slice []interface{})

ToInterSlice converts the given slice to a generic []interface{} slice

func (*Str) ToLower

func (p *Str) ToLower() (new *Str)

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) ToStringSliceG

func (p *Str) ToStringSliceG() (slice []string)

ToStringSliceG converts the underlying slice into a []string slice

func (*Str) ToUpper

func (p *Str) ToUpper() (new *Str)

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

func (p *Str) Trim(cutset ...interface{}) (new *Str)

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

func (p *Str) TrimFunc(f func(rune) bool) (new *Str)

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

func (p *Str) TrimLeft(cutset ...interface{}) (new *Str)

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

func (p *Str) TrimLeftFunc(f func(rune) bool) (new *Str)

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

func (p *Str) TrimPrefix(prefix interface{}) (new *Str)

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

func (p *Str) TrimRight(cutset ...interface{}) (new *Str)

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

func (p *Str) TrimRightFunc(f func(rune) bool) (new *Str)

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

func (p *Str) TrimSuffix(suffix interface{}) (new *Str)

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

func (p *Str) Union(slice interface{}) (new Slice)

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

func (p *Str) UnionM(slice interface{}) Slice

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

func (p *Str) Uniq() (new Slice)

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

func (*Str) UniqM

func (p *Str) UniqM() Slice

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 := NewStrV("1", "2", "3", "3")
fmt.Println(slice.UniqM())
Output:

123

type StringMap

type StringMap map[string]interface{}

StringMap implements the Map 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 YAML constructs.

func LoadYaml

func LoadYaml(filepath string) (m *StringMap)

LoadYaml reads in a yaml file and converts it to a *StringMap

func LoadYamlE

func LoadYamlE(filepath string) (m *StringMap, err error)

LoadYamlE reads in a yaml file and converts it to a *StringMap

func M

func M(obj interface{}) *StringMap

M is an alias to NewStringMap

func MV

func MV(m ...map[string]interface{}) *StringMap

MV is an alias to NewStringMapV

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:

&map[k:v]

func NewStringMapV

func NewStringMapV(m ...map[string]interface{}) *StringMap

NewStringMapV creates a new empty StringMap if nothing given else simply casts the given map to StringMap.

Example

NewStringMapV --------------------------------------------------------------------------------------------------

fmt.Println(NewStringMapV(map[string]interface{}{"k": "v"}))
Output:

&map[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

func ToStringMapE(obj interface{}) (val *StringMap, err error)

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:

&map[1:one] <nil>

func (*StringMap) Any

func (p *StringMap) Any(keys ...interface{}) bool

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

func (p *StringMap) Clear() Map

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:

&map[]

func (*StringMap) Copy

func (p *StringMap) Copy(keys ...interface{}) (new Map)

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:

&map[1:one]

func (*StringMap) Delete

func (p *StringMap) Delete(key interface{}) (val *Object)

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

func (p *StringMap) DeleteM(key interface{}) Map

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:

&map[]

func (*StringMap) Dump

func (p *StringMap) Dump() (pretty string)

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

func (p *StringMap) Exists(key interface{}) bool

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) G

func (p *StringMap) G() map[string]interface{}

G returns the underlying data structure as a Go type.

func (*StringMap) Generic

func (p *StringMap) Generic() bool

Generic returns true if the underlying implementation uses reflection

Example

Generic --------------------------------------------------------------------------------------------------

fmt.Println(NewStringMapV().Generic())
Output:

false

func (*StringMap) Get

func (p *StringMap) Get(key interface{}) (val *Object)

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) Inject

func (p *StringMap) Inject(key string, val interface{}) Map

Inject sets the value for the given key location, using jq type selectors. Returns a reference to this Map.

Example

Inject --------------------------------------------------------------------------------------------------

fmt.Println(NewStringMapV().Inject(".", map[string]interface{}{"1": "one"}))
Output:

&map[1:one]

func (*StringMap) InjectE

func (p *StringMap) InjectE(key string, val interface{}) (m Map, err error)

InjectE sets the value for the given key location, using jq type selectors. Returns a reference to this Map.

func (*StringMap) Keys

func (p *StringMap) Keys() Slice

Keys returns all the keys in this Map as a Slice of the key type.

Example

Keys --------------------------------------------------------------------------------------------------

m := NewStringMapV(map[string]interface{}{"1": "one"})
fmt.Println(m.Keys().O())
Output:

[1]

func (*StringMap) Len

func (p *StringMap) Len() int

Len returns the number of elements in this Map.

Example

Len --------------------------------------------------------------------------------------------------

fmt.Println(NewStringMapV().SetM("k", "v").Len())
Output:

1

func (*StringMap) M

func (p *StringMap) M() (m *StringMap)

M is an alias to ToStringMap

func (*StringMap) MG

func (p *StringMap) MG() (m map[string]interface{})

MG is an alias ToStringMapG

func (*StringMap) Merge

func (p *StringMap) Merge(m Map, location ...string) Map

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. Converting all string maps into *StringMap instances.

Example

Merge --------------------------------------------------------------------------------------------------

fmt.Println(NewStringMapV(map[string]interface{}{"1": "two"}).Merge(NewStringMapV(map[string]interface{}{"1": "one"})))
Output:

&map[1:one]

func (*StringMap) MergeG

func (p *StringMap) MergeG(m Map, location ...string) map[string]interface{}

MergeG modifies this Map by overriding its values with the given map location where they both exist and returns the Go type

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

func (p *StringMap) Query(key string) (val *Object)

Query returns the value at the given key location, using a jq type selectors. Returns empty *Object if not found. see dot notation from https://stedolan.github.io/jq/manual/#Basicfilters with some caveats

Example

Query --------------------------------------------------------------------------------------------------

fmt.Println(ToStringMap("foo:\n  bar: 1\n").Query("foo.bar"))
Output:

1

func (*StringMap) QueryE

func (p *StringMap) QueryE(key string) (val *Object, err error)

QueryE returns the value at the given key location, using a jq type selectors. Returns empty *Object if not found. see dot notation from https://stedolan.github.io/jq/manual/#Basicfilters with some caveats

func (*StringMap) Remove

func (p *StringMap) Remove(key string) Map

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. see dot notation from https://stedolan.github.io/jq/manual/#Basicfilters with some caveats

Example

Remove --------------------------------------------------------------------------------------------------

fmt.Println(ToStringMap("foo:\n  bar: 1\n  foo2: 2\n").Remove("foo.bar"))
Output:

&map[foo:map[foo2:2]]

func (*StringMap) RemoveE

func (p *StringMap) RemoveE(key string) (m Map, err error)

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. see dot notation from https://stedolan.github.io/jq/manual/#Basicfilters with some caveats

func (*StringMap) Set

func (p *StringMap) Set(key, val interface{}) (new bool)

Set the value for the given key to the given val. Returns true if the key did not yet exists in this Map.

Example

Set --------------------------------------------------------------------------------------------------

fmt.Println(NewStringMapV().Set("key", "value"))
Output:

true

func (*StringMap) SetM

func (p *StringMap) SetM(key, val interface{}) Map

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:

&map[k:v]

func (*StringMap) ToStringMap

func (p *StringMap) ToStringMap() (m *StringMap)

ToStringMap converts the map to a *StringMap

func (*StringMap) ToStringMapG

func (p *StringMap) ToStringMapG() (m map[string]interface{})

ToStringMapG converts the map to a Golang map[string]interface{}

func (*StringMap) WriteYaml

func (p *StringMap) WriteYaml(filename string) (err error)

WriteYaml converts the *StringMap into a map[string]interface{} then calls sys.WriteYaml on it to write it out to disk.

type StringMapBool

type StringMapBool map[string]bool

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) (keys *StringSlice, err error)

KeysFromSelector splits the given key selectors into individual keys

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 S

func S(obj interface{}) *StringSlice

S is an alias to ToStringSliceE

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) A

func (p *StringSlice) A() string

A is an alias to String for brevity

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{}) Slice

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{}) Slice

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() Slice

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 Slice)

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{}) Slice

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 Slice)

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) Slice

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) Slice

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() Slice

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) Slice

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) DropLast

func (p *StringSlice) DropLast() Slice

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) Slice

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) Slice

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)) Slice

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) (Slice, 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)) Slice

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

func (p *StringSlice) EachIE(action func(int, O) error) (Slice, error)

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)) Slice

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) (Slice, 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)) Slice

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

func (p *StringSlice) EachRIE(action func(int, O) error) (Slice, error)

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) Slice

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) 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{}) Slice

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) Slice

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) (new *StringSlice)

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()
})
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 Slice)

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{}) Slice

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 Slice)

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() Slice

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) SG

func (p *StringSlice) SG() (slice []string)

SG is an alias to ToStringSliceG

func (*StringSlice) Select

func (p *StringSlice) Select(sel func(O) bool) (new Slice)

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{}) Slice

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{}) (Slice, 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 Slice)

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) 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. 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 Slice)

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() Slice

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 Slice)

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() Slice

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 Slice)

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 Slice)

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) ToInterSlice

func (p *StringSlice) ToInterSlice() (slice []interface{})

ToInterSlice converts the given slice to a generic []interface{} slice

func (*StringSlice) ToStringSlice

func (p *StringSlice) ToStringSlice() (slice *StringSlice)

ToStringSlice converts the underlying slice into a *StringSlice

func (*StringSlice) ToStringSliceG

func (p *StringSlice) ToStringSliceG() (slice []string)

ToStringSliceG converts the underlying slice into a []string slice

func (*StringSlice) Union

func (p *StringSlice) Union(slice interface{}) (new Slice)

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{}) Slice

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 Slice)

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() Slice

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

Directories

Path Synopsis
pkg
bin
Package bin provides some low level binary protocol helpers
Package bin provides some low level binary protocol helpers
cli
Package cli provides some utility functions for command line interfaces
Package cli provides some utility functions for command line interfaces
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
net
Package net provides simple networking helper functions
Package net provides simple networking helper functions
opt
Package opt provides a simple struct for options that can be passed in as an optional last variadic parameter.
Package opt provides a simple struct for options that can be passed in as an optional last variadic parameter.
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
tar
Package tar provides create and extract implementations
Package tar provides create and extract implementations
term
Package term provides TTY helper functions for prompting for passwords etc...
Package term provides TTY helper functions for prompting for passwords etc...
term/test command
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
unit
Package unit provides some helpful unit conversions
Package unit provides some helpful unit conversions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL