n

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 16 Imported by: 1

README

n

build-badge

Nub 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 Nub types.

Requires Go 1.13 and only supports POSIX systems

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

Table of Contents

Nub

Nub provides 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. I've gone to great lengths to implement Nub types for all common Go types and only fall back on Reflection for custom types. This means that in many cases no Reflection is used at all. In the cases where Reflection is used it obviously comes at a cost, which in some cases won't be worth it. However even then 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.

Requirements

The Nub types have been 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

Language Benchmarks

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

Generic 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 when that is required. In the following sections I examine different implementation workarounds for this whole in the language and the cost associated with those implementations.

To do this I'll be implementing a Map function that will for testing purposes also include the creation of the initial slice from a set of seed data as well as iterating over the seed data using a user given lambda to manipulate the data and return a property of the original object then to return this new slice of data as a native type.

I'll use these helper types and functions to generate the test data:

type Integer struct { Value int}
func Range(min, max int) []Integer {
	result := make([]Integer, max-min+1)
	for i := range result {
		result[i] = Bob{min + i
	}
	return result
}
Custom Native - 0x cost

To set a base of comparision we'll implement the desired functionality assuming we know the types i.e. there is nothing that can be reused in this case and a developer must implement their own basic functionality for the new type.

Results from 3 runs after cache warm up:

BenchmarkSlice_CustomNative-16    	2000000000	         0.01 ns/op	       0 B/op	       0 allocs/op
BenchmarkSlice_CustomNative-16    	2000000000	         0.01 ns/op	       0 B/op	       0 allocs/op
BenchmarkSlice_CustomNative-16    	2000000000	         0.01 ns/op	       0 B/op	       0 allocs/op
func BenchmarkSlice_CustomNative(t *testing.B) {
	seedData := RangeInteger(0, 999999)

	// Select the actual values out of the custom object
	lambda := func(x Integer) int {
		return x.Value
	}

	// Because we are assuming the developer isn't reusing anything we know the types
	// and can use them directly
	ints := []int{}
	for i := range seedData {
		ints = append(ints, lambda(seedData[i]))
	}

	assert.Equal(t, 2, ints[2])
	assert.Equal(t, 99999, ints[99999])
}
Pure Reflection - 9x cost

The first and most obvious way to deal with the short coming is to work around it using reflection. Typically whenever reflection comes into the picture there is a 10x cost associated with it. However I wanted to run some of my own benchmarks as a fun exercise.

9x hit from 3 runs after cache warm up:

BenchmarkSlice_PureReflection-16    	2000000000	         0.09 ns/op	       0 B/op	       0 allocs/op
BenchmarkSlice_PureReflection-16    	2000000000	         0.09 ns/op	       0 B/op	       0 allocs/op
BenchmarkSlice_PureReflection-16    	2000000000	         0.09 ns/op	       0 B/op	       0 allocs/op
func BenchmarkSlice_PureReflection(t *testing.B) {
	seedData := RangeInteger(0, 999999)

	// Select the actual values out of the custom object
	lambda := func(x interface{}) interface{} {
		return x.(Integer).Value
	}

	// Use reflection to determine the Kind this would model creating a reference
	// to a new type e.g. NewRefSlice(seed). Because we used reflection we don't
	// need to convert the seed data we can just use the given slice object the
	// way it is.
	var v2 reflect.Value
	v1 := reflect.ValueOf(seedData)
	k1 := v1.Kind()

	// We do need to validate that is a slice type before working with it
	if k1 == reflect.Slice {
		for i := 0; i < v1.Len(); i++ {
			result := lambda(v1.Index(i).Interface())

			// We need to create a new slice based on the result type to store all the results
			if !v2.IsValid() {
				typ := reflect.SliceOf(reflect.TypeOf(result))
				v2 = reflect.MakeSlice(typ, 0, v1.Len())
			}

			// Appending the native type to a reflect.Value of slice is more complicated as we
			// now have to convert the result type into a reflect.Value before appending
			// type asssert the native type.
			v2 = reflect.Append(v2, reflect.ValueOf(result))
		}
	}

	// Now convert the results into a native type
	// Because we created the native slice type as v2 we can simply get its interface and cast
	ints := v2.Interface().([]int)
	assert.Equal(t, 2, ints[2])
	assert.Equal(t, 99999, ints[99999])
}
Slice of interface{} - 14x cost

Now we'll try using the native []interface{} type to accomplish the same task of appending to a given slice a set of values from another slice. I was initially shocked over the results of this as I fully expected this to be faster until I looked a little closer. Because we are working with a slice of interface{} we have go to thank in that we can't simply cast any slice type to a slice of interface. Instead we have to iterate over it and pass in each item to the new []interface{} type. This means that we need to iterate over the entire slice once to convert to a slice of interface then again to execute the lambda over each item then again to convert it into something usable. That is 3 complete loops and we still had to use reflectdion to get into an initial known state.

14x hit from 3 runs after cache warm up:

BenchmarkSlice_SliceOfInterface-16    	2000000000	         0.14 ns/op	       0 B/op	       0 allocs/op
BenchmarkSlice_SliceOfInterface-16    	2000000000	         0.15 ns/op	       0 B/op	       0 allocs/op
BenchmarkSlice_SliceOfInterface-16    	2000000000	         0.14 ns/op	       0 B/op	       0 allocs/op
func BenchmarkSlice_SliceOfInterface(t *testing.B) {
	seedData := RangeInteger(0, 999999)

	// Select the actual values out of the custom object
	lambda := func(x interface{}) interface{} {
		return x.(Integer).Value
	}

	// Use reflection to determine the Kind this would model creating a reference
	// to a new type e.g. NewSlice(seed). Once we've done that we need to convert
	// it into a []interface{}
	v1 := reflect.ValueOf(seedData)
	k1 := v1.Kind()

	// We do need to validate that is a slice type before working with it
	g1 := []interface{}{}
	if k1 == reflect.Slice {
		for i := 0; i < v1.Len(); i++ {
			g1 = append(g1, v1.Index(i).Interface())
		}
	}

	// Now iterate and execute the lambda and create the new result
	results := []interface{}{}
	for i := range g1 {
		results = append(results, lambda(g1[i]))
	}

	// Now convert the results into a native type
	ints := []int{}
	for i := range results {
		ints = append(ints, results[i].(int))
	}
	assert.Equal(t, 2, ints[2])
	assert.Equal(t, 99999, ints[99999])
}
Reflection Assisted - 6.83x cost

Reflection assisted is the notion that we can can develop native types to support common types e.g. []int and provide helper methods for them and fall back on reflection for custom types that are not yet implemented.

8x hit from 3 runs after cache warm up for a custom type using reflection:

BenchmarkSlice_RefSlice-16    	2000000000	         0.08 ns/op	       0 B/op	       0 allocs/op
BenchmarkSlice_RefSlice-16    	2000000000	         0.07 ns/op	       0 B/op	       0 allocs/op
BenchmarkSlice_RefSlice-16    	2000000000	         0.07 ns/op	       0 B/op	       0 allocs/op
func BenchmarkSlice_RefSlice(t *testing.B) {
	ints := NewSlice(RangeInteger(0, 999999)).Map(func(x O) O {
		return x.(Integer).Value
	}).ToInts()
	assert.Equal(t, 2, ints[2])
	assert.Equal(t, 99999, ints[99999])
}

6x hit from 3 runs after cache warm up using IntSlice Nub type:

BenchmarkSlice_IntSlice-16    	2000000000	         0.06 ns/op	       0 B/op	       0 allocs/op
BenchmarkSlice_IntSlice-16    	2000000000	         0.07 ns/op	       0 B/op	       0 allocs/op
BenchmarkSlice_IntSlice-16    	2000000000	         0.06 ns/op	       0 B/op	       0 allocs/op
func BenchmarkSlice_IntSlice(t *testing.B) {
	ints := NewSlice(Range(0, 999999)).Map(func(x O) O {
		return x.(int) + 1
	}).ToInts()
	assert.Equal(t, 3, ints[2])
	assert.Equal(t, 100000, ints[99999])
}

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

• Function names suffixed with 'V' indicates the function is a variation to the function • Function names suffixed with 'V' indicates the function is a variation to the function without the 'V' but accepts variadic input.

• Function names suffixed with 'W' indicates the function is a variation to the function without the 'W' but accepts a lambda expression as input.

• Documentation should be thorough and relied upon for guidance as, for a love of brevity, some functions are named with a single capital letter only. 'G' is being used to export the underlying Go type. 'O' is being used to indicate the interface{} type or to export the underlying Go type as an interface{}. 'S' is used to refer to slice types, 'M' refers to map types, 'A' refers to string types, 'I' ints types, 'R' rune types and combinations may be used to indicate complex types. The documentation will always call out what exactly they mean, but the function name may be cryptic until understood.

Summary of Types

• Char • FloatSlice • IntSlice • InterSlice • Object • RefSlice • Str • StringSlice • StringMap

Index

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:]]+`)
)

TimeLayouts is just a simple wrapper around popular time layouts for time.Parse

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{}, selector ...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 SetOnEmpty

func SetOnEmpty(result *string, value string) string

SetOnEmpty updates the given result string to the given value if it is empty

Example
result := ""
fmt.Println(SetOnEmpty(&result, "foo"))
Output:

foo

func SetOnFalseB

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 SetOnTrueA

func SetOnTrueA(result *string, value string, exp bool) string

SetOnTrueA updates the given result string to the given value if the exp is 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 ToDuration added in v1.1.15

func ToDuration(obj interface{}) (val time.Duration)

ToDuration converts an interface to a time.Duration type.

func ToDurationE added in v1.1.15

func ToDurationE(obj interface{}) (val time.Duration, err error)

ToDurationE converts an interface to a time.Duration type.

func ToFloat32

func ToFloat32(obj interface{}) float32

ToFloat32 convert an interface to a float32 type.

Example

ToFloat32 --------------------------------------------------------------------------------------------------

fmt.Println(ToFloat32("3.1"))
Output:

3.1

func ToFloat32E

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 ToInt16 added in v1.1.15

func ToInt16(obj interface{}) int16

ToInt16 convert an interface to an int16 type.

func ToInt16E added in v1.1.15

func ToInt16E(obj interface{}) (val int16, err error)

ToInt16E convert an interface to an int16 type.

func ToInt32 added in v1.1.15

func ToInt32(obj interface{}) int32

ToInt32 convert an interface to an int32 type.

func ToInt32E added in v1.1.15

func ToInt32E(obj interface{}) (val int32, err error)

ToInt32E convert an interface to an int32 type.

func ToInt64 added in v1.1.15

func ToInt64(obj interface{}) int64

ToInt64 convert an interface to an int64 type.

func ToInt64E added in v1.1.15

func ToInt64E(obj interface{}) (val int64, err error)

ToInt64E convert an interface to an int64 type.

func ToInt8 added in v1.1.15

func ToInt8(obj interface{}) int8

ToInt8 convert an interface to an int8 type.

func ToInt8E added in v1.1.15

func ToInt8E(obj interface{}) (val int8, err error)

ToInt8E convert an interface to an int8 type.

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 ToInts

func ToInts(obj interface{}) []int

ToInts convert an interface to a []int type

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

func ToStringMapGE added in v1.2.0

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

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

func ToStrs

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

ToStrs convert an interface to a []string type.

func ToStrsE

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

ToStrsE convert an interface to a []string type.

Example

ToStrsE --------------------------------------------------------------------------------------------------

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

[1] <nil>

func ToTime added in v1.1.15

func ToTime(obj interface{}) time.Time

ToTime converts an interface to a time.Time type, invalid types will simply return the default time.Time

Example

ToTime --------------------------------------------------------------------------------------------------

fmt.Println(ToTime("2008-01-10"))
Output:

2008-01-10 00:00:00 +0000 UTC

func ToTimeE added in v1.1.15

func ToTimeE(obj interface{}) (val time.Time, err error)

ToTimeE converts an interface to a time.Time type.

func ToUint added in v1.1.15

func ToUint(obj interface{}) uint

ToUint convert an interface to an uint type.

func ToUint16 added in v1.1.15

func ToUint16(obj interface{}) uint16

ToUint16 convert an interface to an uint16 type.

func ToUint16E added in v1.1.15

func ToUint16E(obj interface{}) (val uint16, err error)

ToUint16E convert an interface to an uint16 type.

func ToUint32 added in v1.1.15

func ToUint32(obj interface{}) uint32

ToUint32 convert an interface to an uint32 type.

func ToUint32E added in v1.1.15

func ToUint32E(obj interface{}) (val uint32, err error)

ToUint32E convert an interface to an uint32 type.

func ToUint64 added in v1.1.15

func ToUint64(obj interface{}) uint64

ToUint64 convert an interface to an uint64 type.

func ToUint64E added in v1.1.15

func ToUint64E(obj interface{}) (val uint64, err error)

ToUint64E convert an interface to an uint64 type.

func ToUint8 added in v1.1.15

func ToUint8(obj interface{}) uint8

ToUint8 convert an interface to an uint8 type.

func ToUint8E added in v1.1.15

func ToUint8E(obj interface{}) (val uint8, err error)

ToUint8E convert an interface to an uint8 type.

func ToUintE added in v1.1.15

func ToUintE(obj interface{}) (val uint, err error)

ToUintE convert an interface to an uint type.

func UseLocalTime added in v1.1.42

func UseLocalTime(useLocal bool)

UseLocalTime controls whether the ToTime functions will use UTC or Local for Unix functions

func YAMLArray added in v1.2.0

func YAMLArray(obj interface{}) bool

YAMLArray checks if the given value is array compatible

func YAMLCont

func YAMLCont(obj interface{}) bool

YAMLCont checks if the given value is a valid YAML container

func YAMLMap added in v1.2.0

func YAMLMap(obj interface{}) bool

YAMLMap checks if the given value is map compatible

Types

type Char

type Char rune

Char wraps the Go rune providing a way to distinguish it from an int32 where as a rune is indistinguishable from an int32. Provides convenience methods on par with rapid development languages.

func 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) All added in v1.1.23

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

All tests if this Slice is not empty or optionally if it contains all of the given variadic elements. Incompatible types will return false. Supports all possible int conversions

Example (Contains)
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.All(1))
Output:

true
Example (ContainsAll)
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.All(2, 1))
Output:

true
Example (Empty)

All --------------------------------------------------------------------------------------------------

slice := NewFloatSliceV()
fmt.Println(slice.All())
Output:

false
Example (NotEmpty)
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.All())
Output:

true

func (*FloatSlice) AllS added in v1.1.23

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

AllS tests if this Slice contains all of the given Slice's elements. Incompatible types will return false. Supports FloatSlice, *FloatSlice, []float64 or *[]float64

Example

AllS --------------------------------------------------------------------------------------------------

slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.AllS([]float64{2, 1}))
Output:

true

func (*FloatSlice) Any

func (p *FloatSlice) Any(elems ...interface{}) bool

Any tests if this Slice is not empty or optionally if it contains any of the given variadic elements. Incompatible types will return false. Supports all possible int conversions

Example (Contains)
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Any(1))
Output:

true
Example (ContainsAny)
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Any(0, 1))
Output:

true
Example (Empty)
slice := NewFloatSliceV()
fmt.Println(slice.Any())
Output:

false
Example (NotEmpty)
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Any())
Output:

true

func (*FloatSlice) AnyS

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

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.AnyS([]float64{0, 1}))
Output:

true

func (*FloatSlice) AnyW

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

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.AnyW(func(x O) bool {
	return ExB(x.(float64) == 2)
}))
Output:

true

func (*FloatSlice) Append

func (p *FloatSlice) Append(elem interface{}) ISlice

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

Example
slice := NewFloatSliceV(1).Append(2).Append(3)
fmt.Println(slice)
Output:

[1.000000 2.000000 3.000000]

func (*FloatSlice) AppendV

func (p *FloatSlice) AppendV(elems ...interface{}) ISlice

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

Example
slice := NewFloatSliceV(1).AppendV(2, 3)
fmt.Println(slice)
Output:

[1.000000 2.000000 3.000000]

func (*FloatSlice) At

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

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.At(2))
Output:

3

func (*FloatSlice) Clear

func (p *FloatSlice) Clear() ISlice

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

Example
slice := NewFloatSliceV(1).Concat([]float64{2, 3})
fmt.Println(slice.Clear())
Output:

[]

func (*FloatSlice) Concat

func (p *FloatSlice) Concat(slice interface{}) (new ISlice)

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

Example
slice := NewFloatSliceV(1).Concat([]float64{2, 3})
fmt.Println(slice)
Output:

[1.000000 2.000000 3.000000]

func (*FloatSlice) ConcatM

func (p *FloatSlice) ConcatM(slice interface{}) ISlice

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

Example
slice := NewFloatSliceV(1).ConcatM([]float64{2, 3})
fmt.Println(slice)
Output:

[1.000000 2.000000 3.000000]

func (*FloatSlice) Copy

func (p *FloatSlice) Copy(indices ...int) (new ISlice)

Copy returns a new Slice with the indicated range of elements copied from this Slice. Expects nothing, in which case everything is copied, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Copy())
Output:

[1.000000 2.000000 3.000000]

func (*FloatSlice) Count

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

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

Example
slice := NewFloatSliceV(1, 2, 2)
fmt.Println(slice.Count(2.0))
Output:

2

func (*FloatSlice) CountW

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

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

Example
slice := NewFloatSliceV(1, 2, 2)
fmt.Println(slice.CountW(func(x O) bool {
	return ExB(x.(float64) == 2)
}))
Output:

2

func (*FloatSlice) Drop

func (p *FloatSlice) Drop(indices ...int) ISlice

Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice. Expects nothing, in which case everything is dropped, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that DropAt(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Drop(0, 1))
Output:

[3.000000]

func (*FloatSlice) DropAt

func (p *FloatSlice) DropAt(i int) ISlice

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.DropAt(1))
Output:

[1.000000 3.000000]

func (*FloatSlice) DropFirst

func (p *FloatSlice) DropFirst() ISlice

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.DropFirst())
Output:

[2.000000 3.000000]

func (*FloatSlice) DropFirstN

func (p *FloatSlice) DropFirstN(n int) ISlice

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.DropFirstN(2))
Output:

[3.000000]

func (*FloatSlice) DropLast

func (p *FloatSlice) DropLast() ISlice

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.DropLast())
Output:

[1.000000 2.000000]

func (*FloatSlice) DropLastN

func (p *FloatSlice) DropLastN(n int) ISlice

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.DropLastN(2))
Output:

[1.000000]

func (*FloatSlice) DropW

func (p *FloatSlice) DropW(sel func(O) bool) ISlice

DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice. The slice is updated instantly when lambda expression is evaluated not after DropW completes.

func (*FloatSlice) Each

func (p *FloatSlice) Each(action func(O)) ISlice

Each calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice

Example
NewFloatSliceV(1, 2, 3).Each(func(x O) {
	fmt.Printf("%v", x)
})
Output:

123

func (*FloatSlice) EachE

func (p *FloatSlice) EachE(action func(O) error) (ISlice, error)

EachE calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.

Example
NewFloatSliceV(1, 2, 3).EachE(func(x O) error {
	fmt.Printf("%v", x)
	return nil
})
Output:

123

func (*FloatSlice) EachI

func (p *FloatSlice) EachI(action func(int, O)) ISlice

EachI calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice

Example
NewFloatSliceV(1, 2, 3).EachI(func(i int, x O) {
	fmt.Printf("%v:%v", i, x)
})
Output:

0:11:22:3

func (*FloatSlice) EachIE

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

EachIE calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice and any error from the lambda.

Example
NewFloatSliceV(1, 2, 3).EachIE(func(i int, x O) error {
	fmt.Printf("%v:%v", i, x)
	return nil
})
Output:

0:11:22:3

func (*FloatSlice) EachR

func (p *FloatSlice) EachR(action func(O)) ISlice

EachR calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice

Example
NewFloatSliceV(1, 2, 3).EachR(func(x O) {
	fmt.Printf("%v", x)
})
Output:

321

func (*FloatSlice) EachRE

func (p *FloatSlice) EachRE(action func(O) error) (ISlice, error)

EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.

Example
NewFloatSliceV(1, 2, 3).EachRE(func(x O) error {
	fmt.Printf("%v", x)
	return nil
})
Output:

321

func (*FloatSlice) EachRI

func (p *FloatSlice) EachRI(action func(int, O)) ISlice

EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice

Example
NewFloatSliceV(1, 2, 3).EachRI(func(i int, x O) {
	fmt.Printf("%v:%v", i, x)
})
Output:

2:31:20:1

func (*FloatSlice) EachRIE

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

EachRIE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.

Example
NewFloatSliceV(1, 2, 3).EachRIE(func(i int, x O) error {
	fmt.Printf("%v:%v", i, x)
	return nil
})
Output:

2:31:20:1

func (*FloatSlice) Empty

func (p *FloatSlice) Empty() bool

Empty tests if this Slice is empty.

Example

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

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

true

func (*FloatSlice) First

func (p *FloatSlice) First() (elem *Object)

First returns the first element in this Slice as Object. Object.Nil() == true will be returned when there are no elements in the slice.

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.First())
Output:

1

func (*FloatSlice) FirstN

func (p *FloatSlice) FirstN(n int) ISlice

FirstN returns the first n elements in this slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.

func (*FloatSlice) G

func (p *FloatSlice) G() []float64

G returns the underlying data structure as a builtin Go type

Example

G --------------------------------------------------------------------------------------------------

fmt.Println(NewFloatSliceV(1, 2, 3).G())
Output:

[1 2 3]

func (*FloatSlice) Index

func (p *FloatSlice) Index(elem interface{}) (loc int)

Index returns the index of the first element in this Slice where element == elem Returns a -1 if the element was not not found.

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Index(2))
Output:

1

func (*FloatSlice) Insert

func (p *FloatSlice) Insert(i int, obj interface{}) ISlice

Insert modifies this Slice to insert the given elements before the element(s) with the given index. Negative indices count backwards from the end of the slice, where -1 is the last element. If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice. If a Slice is given all elements will be inserted starting from the beging until the end. Slice is returned for chaining. Invalid index locations will not change the slice.

Example
slice := NewFloatSliceV(1, 3)
fmt.Println(slice.Insert(1, 2))
Output:

[1.000000 2.000000 3.000000]

func (*FloatSlice) InterSlice

func (p *FloatSlice) InterSlice() bool

InterSlice returns true if the underlying implementation is a RefSlice

func (*FloatSlice) Join

func (p *FloatSlice) Join(separator ...string) (str *Object)

Join converts each element into a string then joins them together using the given separator or comma by default.

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Join())
Output:

1,2,3

func (*FloatSlice) Last

func (p *FloatSlice) Last() (elem *Object)

Last returns the last element in this Slice as an Object. Object.Nil() == true will be returned if there are no elements in the slice.

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Last())
Output:

3

func (*FloatSlice) LastN

func (p *FloatSlice) LastN(n int) ISlice

LastN returns the last n elements in this Slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.LastN(2))
Output:

[2.000000 3.000000]

func (*FloatSlice) Len

func (p *FloatSlice) Len() int

Len returns the number of elements in this Slice

Example

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

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

3

func (*FloatSlice) Less

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

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

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

false

func (*FloatSlice) Map

func (p *FloatSlice) Map(mod func(O) O) ISlice

Map creates a new slice with the modified elements from the lambda.

func (*FloatSlice) Nil

func (p *FloatSlice) Nil() bool

Nil tests if this Slice is nil

Example

Nil --------------------------------------------------------------------------------------------------

var slice *FloatSlice
fmt.Println(slice.Nil())
Output:

true

func (*FloatSlice) O

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

O returns the underlying data structure as is

Example

O --------------------------------------------------------------------------------------------------

fmt.Println(NewFloatSliceV(1, 2, 3))
Output:

[1.000000 2.000000 3.000000]

func (*FloatSlice) Pair

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

Pair simply returns the first and second Slice elements as Objects

Example
slice := NewFloatSliceV(1, 2)
first, second := slice.Pair()
fmt.Println(first, second)
Output:

1 2

func (*FloatSlice) Pop

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

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Pop())
Output:

3

func (*FloatSlice) PopN

func (p *FloatSlice) PopN(n int) (new ISlice)

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.PopN(2))
Output:

[2.000000 3.000000]

func (*FloatSlice) Prepend

func (p *FloatSlice) Prepend(elem interface{}) ISlice

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

Example
slice := NewFloatSliceV(2, 3)
fmt.Println(slice.Prepend(1))
Output:

[1.000000 2.000000 3.000000]

func (*FloatSlice) RefSlice

func (p *FloatSlice) RefSlice() bool

RefSlice returns true if the underlying implementation is a RefSlice

func (*FloatSlice) Reverse

func (p *FloatSlice) Reverse() (new ISlice)

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Reverse())
Output:

[3.000000 2.000000 1.000000]

func (*FloatSlice) ReverseM

func (p *FloatSlice) ReverseM() ISlice

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.ReverseM())
Output:

[3.000000 2.000000 1.000000]

func (*FloatSlice) S

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

S is an alias to ToStringSlice

func (*FloatSlice) Select

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

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Select(func(x O) bool {
	return ExB(x.(float64) == 2 || x.(float64) == 3)
}))
Output:

[2.000000 3.000000]

func (*FloatSlice) Set

func (p *FloatSlice) Set(i int, elems interface{}) ISlice

Set the element(s) at the given index location to the given element(s). Allows for negative notation. Returns a reference to this Slice and swallows any errors.

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Set(0, 0))
Output:

[0.000000 2.000000 3.000000]

func (*FloatSlice) SetE

func (p *FloatSlice) SetE(i int, elems interface{}) (ISlice, error)

SetE the element(s) at the given index location to the given element(s). Allows for negative notation. Returns a referenc to this Slice and an error if out of bounds or elem is the wrong type.

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.SetE(0, 0))
Output:

[0.000000 2.000000 3.000000] <nil>

func (*FloatSlice) Shift

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

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Shift())
Output:

1

func (*FloatSlice) ShiftN

func (p *FloatSlice) ShiftN(n int) (new ISlice)

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

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.ShiftN(2))
Output:

[1.000000 2.000000]

func (*FloatSlice) Single

func (p *FloatSlice) Single() bool

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

func (*FloatSlice) Slice

func (p *FloatSlice) Slice(indices ...int) ISlice

Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation. Expects nothing, in which case everything is included, or two indices i and j, in which case an inclusive behavior is used such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.

e.g. NewFloatSliceV(1,2,3).Slice(0, -1) == [1,2,3] && NewFloatSliceV(1,2,3).Slice(1,2) == [2,3]

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Slice(1, -1))
Output:

[2.000000 3.000000]

func (*FloatSlice) Sort

func (p *FloatSlice) Sort() (new ISlice)

Sort returns a new Slice with sorted elements.

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

[1.000000 2.000000 3.000000]

func (*FloatSlice) SortM

func (p *FloatSlice) SortM() ISlice

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

Example
slice := NewFloatSliceV(2, 3, 1)
fmt.Println(slice.SortM())
Output:

[1.000000 2.000000 3.000000]

func (*FloatSlice) SortReverse

func (p *FloatSlice) SortReverse() (new ISlice)

SortReverse returns a new Slice sorting the elements in reverse.

Example
slice := NewFloatSliceV(2, 3, 1)
fmt.Println(slice.SortReverse())
Output:

[3.000000 2.000000 1.000000]

func (*FloatSlice) SortReverseM

func (p *FloatSlice) SortReverseM() ISlice

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

Example
slice := NewFloatSliceV(2, 3, 1)
fmt.Println(slice.SortReverseM())
Output:

[3.000000 2.000000 1.000000]

func (*FloatSlice) String

func (p *FloatSlice) String() string

Returns a string representation of this Slice, implements the Stringer interface

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice)
Output:

[1.000000 2.000000 3.000000]

func (*FloatSlice) Swap

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

Swap modifies this Slice swapping the indicated elements.

Example
slice := NewFloatSliceV(2, 3, 1)
slice.Swap(0, 2)
slice.Swap(1, 2)
fmt.Println(slice)
Output:

[1.000000 2.000000 3.000000]

func (*FloatSlice) Take

func (p *FloatSlice) Take(indices ...int) (new ISlice)

Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice. Expects nothing, in which case everything is taken, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Take(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.Take(0, 1))
Output:

[1.000000 2.000000]

func (*FloatSlice) TakeAt

func (p *FloatSlice) TakeAt(i int) (elem *Object)

TakeAt modifies this Slice removing the elemement at the given index location and returns the removed element as an Object. Allows for negative notation.

Example
slice := NewFloatSliceV(1, 2, 3)
fmt.Println(slice.TakeAt(1))
Output:

2

func (*FloatSlice) TakeW

func (p *FloatSlice) TakeW(sel func(O) bool) (new ISlice)

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

func (*FloatSlice) ToIntSlice

func (p *FloatSlice) ToIntSlice() (slice *IntSlice)

ToIntSlice converts the underlying slice into a *IntSlice

func (*FloatSlice) ToInterSlice

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

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

func (*FloatSlice) ToInts

func (p *FloatSlice) ToInts() (slice []int)

ToInts converts the underlying slice into a []int

func (*FloatSlice) ToStringSlice

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

ToStringSlice converts the underlying slice into a *StringSlice

func (*FloatSlice) ToStrs

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

ToStrs converts the underlying slice into a []string slice

func (*FloatSlice) Union

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

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

Example
slice := NewFloatSliceV(1, 2)
fmt.Println(slice.Union([]float64{2, 3}))
Output:

[1.000000 2.000000 3.000000]

func (*FloatSlice) UnionM

func (p *FloatSlice) UnionM(slice interface{}) ISlice

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

Example
slice := NewFloatSliceV(1, 2)
fmt.Println(slice.UnionM([]float64{2, 3}))
Output:

[1.000000 2.000000 3.000000]

func (*FloatSlice) Uniq

func (p *FloatSlice) Uniq() (new ISlice)

Uniq returns a new Slice with all non uniq elements removed while preserving element order. Cost for this call vs the UniqM is roughly the same, this one is appending that one dropping.

Example
slice := NewFloatSliceV(1, 2, 3, 3)
fmt.Println(slice.Uniq())
Output:

[1.000000 2.000000 3.000000]

func (*FloatSlice) UniqM

func (p *FloatSlice) UniqM() ISlice

UniqM modifies this Slice to remove all non uniq elements while preserving element order. Cost for this call vs the Uniq is roughly the same, this one is dropping that one appending.

Example
slice := NewFloatSliceV(1, 2, 3, 3)
fmt.Println(slice.UniqM())
Output:

[1.000000 2.000000 3.000000]

type IF

type IF struct {
	State  bool          // Status of the result
	Error  error         // Errors that may have been captured
	Return []interface{} // Return values
}

IF provides a way to deal with conditionals more elegantly in Go

func If

func If(state bool, err ...error) *IF

If provides a way to execute one line conditionals in Go

func (*IF) Do

func (cond *IF) Do(f interface{}, params ...interface{}) *IF

Do executes the given function f with the given paramaters p if IF.State is true. When IF.State is true the IF object is Reset and the properties are used for the state of the current Do execution returning all return values from the function given to Do in the IF.Return slice and the first identified return bool will be used for IF.State and the first identified return error will be used for IF.Error.

func (*IF) Reset

func (cond *IF) Reset() *IF

Reset defaults all the IF properties

type IMap added in v1.1.15

type IMap interface {
	Any(keys ...interface{}) bool // Any tests if this Map is not empty or optionally if it contains any of the given variadic keys.
	// AnyS(slice interface{}) bool                      // AnyS tests if this Map contains any of the given Slice's elements.
	// AnyW(sel func(O) bool) bool                       // AnyW tests if this Map contains any that match the lambda selector.
	// Append(elem interface{}) Slice                    // Append an element to the end of this Map and returns a reference to this Map.
	// AppendV(elems ...interface{}) Slice               // AppendV appends the variadic elements to the end of this Map and returns a reference to this Map.
	Clear() IMap // Clear modifies this Map to clear out all key-value pairs and returns a reference to this Map.
	// Concat(slice interface{}) (new Slice)             // Concat returns a new Slice by appending the given Slice to this Map using variadic expansion.
	// ConcatM(slice interface{}) Slice                  // ConcatM modifies this Map by appending the given Slice using variadic expansion and returns a reference to this Map.
	Copy(keys ...interface{}) (new IMap) // Copy returns a new Map with the indicated key-value pairs copied from this Map or all if not given.
	// Count(elem interface{}) (cnt int)                 // Count the number of elements in this Map equal to the given element.
	// CountW(sel func(O) bool) (cnt int)                // CountW counts the number of elements in this Map that match the lambda selector.
	Delete(key interface{}) (val *Object) // Delete modifies this Map to delete the indicated key-value pair and returns the value from the Map.
	DeleteM(key interface{}) IMap         // DeleteM modifies this Map to delete the indicated key-value pair and returns a reference to this Map rather than the key-value pair.
	//DeleteS(keys interface{}) (obj *Object) // DeleteS modifies this Map to delete the indicated key-value pairs and returns the values from the Map as a Slice.
	Exists(key interface{}) bool // Exists checks if the given key exists in this Map.
	// DeleteW(sel func(O) bool) Slice                     // DropW modifies this Map to delete the elements that match the lambda selector and returns a reference to this Map.
	// Each(action func(O)) Slice                        // Each calls the given lambda once for each element in this Map, passing in that element
	// EachE(action func(O) error) (ISlice, error)        // EachE calls the given lambda once for each element in this Map, passing in that element
	// EachI(action func(int, O)) Slice                  // EachI calls the given lambda once for each element in this Map, passing in the index and element
	// EachIE(action func(int, O) error) (ISlice, error)  // EachIE calls the given lambda once for each element in this Map, passing in the index and element
	// EachR(action func(O)) Slice                       // EachR calls the given lambda once for each element in this Map in reverse, passing in that element
	// EachRE(action func(O) error) (ISlice, error)       // EachRE calls the given lambda once for each element in this Map in reverse, passing in that element
	// EachRI(action func(int, O)) Slice                 // EachRI calls the given lambda once for each element in this Map in reverse, passing in that element
	// EachRIE(action func(int, O) error) (ISlice, error) // EachRIE calls the given lambda once for each element in this Map in reverse, passing in that element
	// Empty() bool                                      // Empty tests if this Map is empty.
	Generic() bool                                                // Generic returns true if the underlying implementation uses reflection
	Get(key interface{}) (val *Object)                            // Get returns the value at the given key location. Returns empty *Object if not found.
	Update(selector string, val interface{}) IMap                 // Update sets the value for the given key location, using jq type selectors. Returns a reference to this Map.
	UpdateE(selector string, val interface{}) (m IMap, err error) // UpdateE sets the value for the given key location, using jq type selectors. Returns a reference to this Map.
	// Join(separator ...string) (str *Object)           // Join converts each element into a string then joins them together using the given separator or comma by default.
	Keys() ISlice                          // Keys returns all the keys in this Map as a Slice of the key type.
	Len() int                              // Len returns the number of elements in this Map.
	M() (m *StringMap)                     // M is an alias to ToStringMap
	MG() (m map[string]interface{})        // MG is an alias to ToStringMapG
	Merge(m IMap, location ...string) IMap // Merge modifies this Map by overriding its values at location with the given map where they both exist and returns a reference to this Map.
	// Less(i, j int) bool                               // Less returns true if the element indexed by i is less than the element indexed by j.
	// Nil() bool                                        // Nil tests if this Map is nil.
	O() interface{} // O returns the underlying data structure as is.
	// Pair() (first, second *Object)                    // Pair simply returns the first and second Slice elements as Objects.
	// Pop() (elem *Object)                              // Pop modifies this Map to remove the last element and returns the removed element as an Object.
	// PopN(n int) (new Map)                           // PopN modifies this Map to remove the last n elements and returns the removed elements as a new Map.
	// Prepend(elem interface{}) Slice                   // Prepend modifies this Map to add the given element at the begining and returns a reference to this Map.
	Query(selector string, params ...interface{}) (val *Object)             // Query returns the value at the given selector location, using jq type selectors. Returns empty *Object if not found.
	QueryE(selector string, params ...interface{}) (val *Object, err error) // Query returns the value at the given selector location, using jq type selectors. Returns empty *Object if not found.
	Remove(selector string, params ...interface{}) IMap                     // Remove modifies this map to remove the value at the given selector location, using jq type selectors. Returns a reference to this Map
	RemoveE(selector string, params ...interface{}) (m IMap, err error)     // RemoveE modifies this map to remove the value at the given selector location, using jq type selectors. Returns a reference to this Map
	// Reverse() (new Map)                             // Reverse returns a new Map with the order of the elements reversed.
	// ReverseM() Slice                                  // ReverseM modifies this Map reversing the order of the elements and returns a reference to this Map.
	// Select(sel func(O) bool) (new Map)              // Select creates a new Map with the elements that match the lambda selector.
	Set(selector, val interface{}) bool  // Set the value for the given key to the given val. Returns true if the selector did not yet exists in this Map.
	SetM(selector, val interface{}) IMap // SetM the value for the given selector to the given val creating map if necessary. Returns a reference to this Map.
	// Shift() (elem *Object)                            // Shift modifies this Map to remove the first element and returns the removed element as an Object.
	// ShiftN(n int) (new Map)                         // ShiftN modifies this Map to remove the first n elements and returns the removed elements as a new Map.
	// Single() bool                                     // Single reports true if there is only one element in this Map.
	// Slice(indices ...int) Slice                       // Slice returns a range of elements from this Map as a Slice reference to the original. Allows for negative notation.
	// Sort() (new Map)                                // Sort returns a new Map with sorted elements.
	// SortM() Slice                                     // SortM modifies this Map sorting the elements and returns a reference to this Map.
	// SortReverse() (new Map)                         // SortReverse returns a new Map sorting the elements in reverse.
	// SortReverseM() Slice                              // SortReverseM modifies this Map sorting the elements in reverse and returns a reference to this Map.
	// String() string                                   // Returns a string representation of this Map, implements the Stringer interface
	// Swap(i, j int)                                    // Swap modifies this Map swapping the indicated elements.
	ToStringMap() (m *StringMap)              // ToStringMap converts the map to a *StringMap
	ToStringMapG() (m map[string]interface{}) // ToStringMapG converts the map to a Golang map[string]interface{}
	// Take(indices ...int) (new Map)                  // Take modifies this Map removing the indicated range of elements from this Map and returning them as a new Map.
	// TakeAt(i int) (elem *Object)                      // TakeAt modifies this Map removing the elemement at the given index location and returns the removed element as an Object.
	// TakeW(sel func(O) bool) (new Map)               // TakeW modifies this Map removing the elements that match the lambda selector and returns them as a new Map.
	// Union(slice interface{}) (new Map)              // Union returns a new Map by joining uniq elements from this Map with uniq elements from the given Slice while preserving order.
	// UnionM(slice interface{}) Slice                   // UnionM modifies this Map by joining uniq elements from this Map with uniq elements from the given Slice while preserving order.
	// Uniq() (new Map)                                // Uniq returns a new Map with all non uniq elements removed while preserving element order.
	// UniqM() Slice                                     // UniqM modifies this Map to remove all non uniq elements while preserving element order.
	YAML() (data string)                   // YAML converts the Map into a YAML string
	YAMLE() (data string, err error)       // YAMLE converts the Map into a YAML string
	WriteJSON(filename string) (err error) // WriteJSON converts the Map into a map[string]interface{} then calls json.WriteJSON on it to write it out to disk.
	WriteYAML(filename string) (err error) // WriteYAML converts the Map into a map[string]interface{} then calls yaml.WriteYAML on it to write it out to disk.
}

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

type ISlice

type ISlice interface {
	A() string                                         // A is an alias to String for brevity
	All(elems ...interface{}) bool                     // All tests if this Slice is not empty or optionally if it contains all of the given variadic elements.
	AllS(slice interface{}) bool                       // AnyS tests if this Slice contains all of the given Slice's elements.
	Any(elems ...interface{}) bool                     // Any tests if this Slice is not empty or optionally if it contains any of the given variadic elements.
	AnyS(slice interface{}) bool                       // AnyS tests if this Slice contains any of the given Slice's elements.
	AnyW(sel func(O) bool) bool                        // AnyW tests if this Slice contains any that match the lambda selector.
	Append(elem interface{}) ISlice                    // Append an element to the end of this Slice and returns a reference to this Slice.
	AppendV(elems ...interface{}) ISlice               // AppendV appends the variadic elements to the end of this Slice and returns a reference to this Slice.
	At(i int) (elem *Object)                           // At returns the element at the given index location. Allows for negative notation.
	Clear() ISlice                                     // Clear modifies this Slice to clear out all elements and returns a reference to this Slice.
	Concat(slice interface{}) (new ISlice)             // Concat returns a new Slice by appending the given Slice to this Slice using variadic expansion.
	ConcatM(slice interface{}) ISlice                  // ConcatM modifies this Slice by appending the given Slice using variadic expansion and returns a reference to this Slice.
	Copy(indices ...int) (new ISlice)                  // Copy returns a new Slice with the indicated range of elements copied from this Slice.
	Count(elem interface{}) (cnt int)                  // Count the number of elements in this Slice equal to the given element.
	CountW(sel func(O) bool) (cnt int)                 // CountW counts the number of elements in this Slice that match the lambda selector.
	Drop(indices ...int) ISlice                        // Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice.
	DropAt(i int) ISlice                               // DropAt modifies this Slice to delete the element at the given index location. Allows for negative notation.
	DropFirst() ISlice                                 // DropFirst modifies this Slice to delete the first element and returns a reference to this Slice.
	DropFirstN(n int) ISlice                           // DropFirstN modifies this Slice to delete the first n elements and returns a reference to this Slice.
	DropLast() ISlice                                  // DropLast modifies this Slice to delete the last element and returns a reference to this Slice.
	DropLastN(n int) ISlice                            // DropLastN modifies thi Slice to delete the last n elements and returns a reference to this Slice.
	DropW(sel func(O) bool) ISlice                     // DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice.
	Each(action func(O)) ISlice                        // Each calls the given lambda once for each element in this Slice, passing in that element
	EachE(action func(O) error) (ISlice, error)        // EachE calls the given lambda once for each element in this Slice, passing in that element
	EachI(action func(int, O)) ISlice                  // EachI calls the given lambda once for each element in this Slice, passing in the index and element
	EachIE(action func(int, O) error) (ISlice, error)  // EachIE calls the given lambda once for each element in this Slice, passing in the index and element
	EachR(action func(O)) ISlice                       // EachR calls the given lambda once for each element in this Slice in reverse, passing in that element
	EachRE(action func(O) error) (ISlice, error)       // EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element
	EachRI(action func(int, O)) ISlice                 // EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element
	EachRIE(action func(int, O) error) (ISlice, error) // EachRIE calls the given lambda once for each element in this Slice in reverse, passing in that element
	Empty() bool                                       // Empty tests if this Slice is empty.
	First() (elem *Object)                             // First returns the first element in this Slice as Object.
	FirstN(n int) ISlice                               // FirstN returns the first n elements in this slice as a Slice reference to the original.
	InterSlice() bool                                  // Generic returns true if the underlying implementation uses reflection
	Index(elem interface{}) (loc int)                  // Index returns the index of the first element in this Slice where element == elem
	Insert(i int, elem interface{}) ISlice             // Insert modifies this Slice to insert the given element(s) before the element with the given index.
	Join(separator ...string) (str *Object)            // Join converts each element into a string then joins them together using the given separator or comma by default.
	Last() (elem *Object)                              // Last returns the last element in this Slice as an Object.
	LastN(n int) ISlice                                // LastN returns the last n elements in this Slice as a Slice reference to the original.
	Len() int                                          // Len returns the number of elements in this Slice.
	Less(i, j int) bool                                // Less returns true if the element indexed by i is less than the element indexed by j.
	Nil() bool                                         // Nil tests if this Slice is nil.
	Map(mod func(O) O) ISlice                          // Map creates a new slice with the modified elements from the lambda.
	O() interface{}                                    // O returns the underlying data structure as is.
	Pair() (first, second *Object)                     // Pair simply returns the first and second Slice elements as Objects.
	Pop() (elem *Object)                               // Pop modifies this Slice to remove the last element and returns the removed element as an Object.
	PopN(n int) (new ISlice)                           // PopN modifies this Slice to remove the last n elements and returns the removed elements as a new Slice.
	Prepend(elem interface{}) ISlice                   // Prepend modifies this Slice to add the given element at the begining and returns a reference to this Slice.
	RefSlice() bool                                    // RefSlice returns true if the underlying implementation is a RefSlice
	Reverse() (new ISlice)                             // Reverse returns a new Slice with the order of the elements reversed.
	ReverseM() ISlice                                  // ReverseM modifies this Slice reversing the order of the elements and returns a reference to this Slice.
	S() (slice *StringSlice)                           // S is an alias to ToStringSlice
	Select(sel func(O) bool) (new ISlice)              // Select creates a new slice with the elements that match the lambda selector.
	Set(i int, elems interface{}) ISlice               // Set the element(s) at the given index location to the given element(s). Allows for negative notation.
	SetE(i int, elems interface{}) (ISlice, error)     // SetE the element(s) at the given index location to the given element(s). Allows for negative notation.
	Shift() (elem *Object)                             // Shift modifies this Slice to remove the first element and returns the removed element as an Object.
	ShiftN(n int) (new ISlice)                         // ShiftN modifies this Slice to remove the first n elements and returns the removed elements as a new Slice.
	Single() bool                                      // Single reports true if there is only one element in this Slice.
	Slice(indices ...int) ISlice                       // Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation.
	Sort() (new ISlice)                                // Sort returns a new Slice with sorted elements.
	SortM() ISlice                                     // SortM modifies this Slice sorting the elements and returns a reference to this Slice.
	SortReverse() (new ISlice)                         // SortReverse returns a new Slice sorting the elements in reverse.
	SortReverseM() ISlice                              // SortReverseM modifies this Slice sorting the elements in reverse and returns a reference to this Slice.
	String() string                                    // String returns a string representation of this Slice, implements the Stringer interface
	Swap(i, j int)                                     // Swap modifies this Slice swapping the indicated elements.
	Take(indices ...int) (new ISlice)                  // Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice.
	TakeAt(i int) (elem *Object)                       // TakeAt modifies this Slice removing the elemement at the given index location and returns the removed element as an Object.
	TakeW(sel func(O) bool) (new ISlice)               // TakeW modifies this Slice removing the elements that match the lambda selector and returns them as a new Slice.
	ToInts() (slice []int)                             // ToInts converts the given slice into a native []int type
	ToIntSlice() (slice *IntSlice)                     // ToIntSlice converts the given slice into a *IntSlice
	ToInterSlice() (slice []interface{})               // ToInterSlice converts the given slice to a generic []interface{} slice
	ToStrs() (slice []string)                          // ToStrs converts the underlying slice into a []string slice
	ToStringSlice() (slice *StringSlice)               // ToStringSlice converts the underlying slice into a *StringSlice
	Union(slice interface{}) (new ISlice)              // Union returns a new Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order.
	UnionM(slice interface{}) ISlice                   // UnionM modifies this Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order.
	Uniq() (new ISlice)                                // Uniq returns a new Slice with all non uniq elements removed while preserving element order.
	UniqM() ISlice                                     // UniqM modifies this Slice to remove all non uniq elements while preserving element order.
}

ISlice provides a generic way to work with slice types providing convenience methods on par with rapid development languages. 'this Slice' refers to the current slice instance being operated on. 'new Slice' refers to a copy of the slice based on a new underlying Array.

func NewSliceV

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

NewSliceV creates a new Slice encapsulating the given variadic elements in a new Slice of that type using type assertion for optimized types. Non optimized types will fall back on reflection to generically handle the type incurring the full 10x reflection processing overhead. In the case where nothing is given a new *RefSlice will be returned.

Optimized: []int, []string, Str

func Slice added in v1.1.9

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

Slice provides a generic way to work with Slice types. It does this by wrapping Go types directly for optimized types thus avoiding reflection processing overhead and making a plethora of Slice methods available. Non optimized types will fall back on reflection to generically handle the type incurring the full 10x reflection processing overhead.

Optimized: []int, []string, StrSlice

type IntMapBool

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) All added in v1.1.23

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

All tests if this Slice is not empty or optionally if it contains all of the given variadic elements. Incompatible types will return false. Supports all possible int conversions

Example (Contains)
slice := NewIntSliceV(1, 2, 3)
fmt.Println(slice.All(1))
Output:

true
Example (ContainsAll)
slice := NewIntSliceV(1, 2, 3)
fmt.Println(slice.All(2, 1))
Output:

true
Example (Empty)

All --------------------------------------------------------------------------------------------------

slice := NewIntSliceV()
fmt.Println(slice.All())
Output:

false
Example (NotEmpty)
slice := NewIntSliceV(1, 2, 3)
fmt.Println(slice.All())
Output:

true

func (*IntSlice) AllS added in v1.1.23

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

AllS tests if this Slice contains all of the given Slice's elements. Incompatible types will return false. Supports IntSlice, *IntSlice, []int or *[]int

Example

AllS --------------------------------------------------------------------------------------------------

slice := NewIntSliceV(1, 2, 3)
fmt.Println(slice.AllS([]int{2, 1}))
Output:

true

func (*IntSlice) Any

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

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

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

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

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

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

Copy returns a new Slice with the indicated range of elements copied from this Slice. Expects nothing, in which case everything is copied, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.

Example
slice := 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) ISlice

Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice. Expects nothing, in which case everything is dropped, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that DropAt(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

Example
slice := NewIntSliceV(1, 2, 3)
fmt.Println(slice.Drop(0, 1))
Output:

[3]

func (*IntSlice) DropAt

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

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

Example
slice := NewIntSliceV(1, 2, 3)
fmt.Println(slice.DropAt(1))
Output:

[1 3]

func (*IntSlice) DropFirst

func (p *IntSlice) DropFirst() ISlice

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

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

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

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

DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice. The slice is updated instantly when lambda expression is evaluated not after DropW completes.

Example
slice := 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)) ISlice

Each calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice

Example
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) (ISlice, error)

EachE calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.

Example
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)) ISlice

EachI calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice

Example
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) (ISlice, 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)) ISlice

EachR calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice

Example
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) (ISlice, error)

EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.

Example
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)) ISlice

EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice

Example
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) (ISlice, 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) ISlice

FirstN returns the first n elements in this slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.

Example
slice := 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{}) ISlice

Insert modifies this Slice to insert the given elements before the element(s) with the given index. Negative indices count backwards from the end of the slice, where -1 is the last element. If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice. If a Slice is given all elements will be inserted starting from the beging until the end. Slice is returned for chaining. Invalid index locations will not change the slice.

Example
slice := 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) ISlice

LastN returns the last n elements in this Slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.

Example
slice := 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) Map

func (p *IntSlice) Map(mod func(O) O) ISlice

Map creates a new slice with the modified elements from the lambda.

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

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

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

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

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

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

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

Set the element(s) at the given index location to the given element(s). Allows for negative notation. Returns a reference to this Slice and swallows any errors.

Example
slice := 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{}) (ISlice, error)

SetE the element(s) at the given index location to the given element(s). Allows for negative notation. Returns a referenc to this Slice and an error if out of bounds or elem is the wrong type.

Example
slice := 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 ISlice)

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

Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation. Expects nothing, in which case everything is included, or two indices i and j, in which case an inclusive behavior is used such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.

e.g. 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 ISlice)

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

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

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

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

Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice. Expects nothing, in which case everything is taken, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Take(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

Example
slice := 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 ISlice)

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

Example
slice := NewIntSliceV(1, 2, 3)
fmt.Println(slice.TakeW(func(x O) bool {
	return ExB(x.(int)%2 == 0)
}))
Output:

[2]

func (*IntSlice) ToIntSlice

func (p *IntSlice) ToIntSlice() (slice *IntSlice)

ToIntSlice converts the underlying slice into a *IntSlice

func (*IntSlice) ToInterSlice

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

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

func (*IntSlice) ToInts

func (p *IntSlice) ToInts() (slice []int)

ToInts converts the underlying slice into a []int

func (*IntSlice) ToStringSlice

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

ToStringSlice converts the underlying slice into a *StringSlice

func (*IntSlice) ToStrs

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

ToStrs converts the underlying slice into a []string slice

func (*IntSlice) Union

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

Union returns a new Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports 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{}) ISlice

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

Uniq returns a new Slice with all non uniq elements removed while preserving element order. Cost for this call vs the UniqM is roughly the same, this one is appending that one dropping.

Example
slice := NewIntSliceV(1, 2, 3, 3)
fmt.Println(slice.Uniq())
Output:

[1 2 3]

func (*IntSlice) UniqM

func (p *IntSlice) UniqM() ISlice

UniqM modifies this Slice to remove all non uniq elements while preserving element order. Cost for this call vs the Uniq is roughly the same, this one is dropping that one appending.

Example
slice := 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 ToSlice

func ToSlice(obj interface{}) (slice *InterSlice)

ToSlice is an alias to ToInterSlice

func (*InterSlice) A

func (p *InterSlice) A() string

A is an alias to String for brevity

func (*InterSlice) All added in v1.1.23

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

All tests if this Slice is not empty or optionally if it contains all of the given variadic elements. Incompatible types will return false.

Example (Contains)
slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.All(1))
Output:

true
Example (ContainsAll)
slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.All(2, 1))
Output:

true
Example (Empty)

All --------------------------------------------------------------------------------------------------

slice := NewInterSliceV()
fmt.Println(slice.All())
Output:

false
Example (NotEmpty)
slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.All())
Output:

true

func (*InterSlice) AllS added in v1.1.23

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

AllS tests if this Slice contains all of the given Slice's elements. Incompatible types will return false. Supports InterSlice, *InterSlice, Slice and Go slice types

Example

AllS --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.AllS([]int{2, 1}))
Output:

true

func (*InterSlice) Any

func (p *InterSlice) Any(elems ...interface{}) bool

Any tests if this Slice is not empty or optionally if it contains any of the given variadic elements. Incompatible types will return false.

Example (Contains)
slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Any(1))
Output:

true
Example (ContainsAny)
slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Any(0, 1))
Output:

true
Example (Empty)

Any --------------------------------------------------------------------------------------------------

slice := NewInterSliceV()
fmt.Println(slice.Any())
Output:

false
Example (NotEmpty)
slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Any())
Output:

true

func (*InterSlice) AnyS

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

AnyS tests if this Slice contains any of the given Slice's elements. Incompatible types will return false. Supports InterSlice, *InterSlice, Slice and Go slice types

Example

AnyS --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.AnyS([]int{0, 1}))
Output:

true

func (*InterSlice) AnyW

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

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

Example

AnyW --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.AnyW(func(x O) bool {
	return ExB(x.(int) == 2)
}))
Output:

true

func (*InterSlice) Append

func (p *InterSlice) Append(elem interface{}) ISlice

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

Example

Append --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1).Append(2).Append(3)
fmt.Println(slice.O())
Output:

[1 2 3]

func (*InterSlice) AppendV

func (p *InterSlice) AppendV(elems ...interface{}) ISlice

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

Example

AppendV --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1).AppendV(2, 3)
fmt.Println(slice.O())
Output:

[1 2 3]

func (*InterSlice) At

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

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

Example

At --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.At(2).O())
Output:

3

func (*InterSlice) Clear

func (p *InterSlice) Clear() ISlice

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

Example

Clear --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1).ConcatM([]int{2, 3})
fmt.Println(slice.Clear().O())
Output:

[]

func (*InterSlice) Concat

func (p *InterSlice) Concat(slice interface{}) (new ISlice)

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

Example

Concat --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1).Concat([]int{2, 3})
fmt.Println(slice.O())
Output:

[1 2 3]

func (*InterSlice) ConcatM

func (p *InterSlice) ConcatM(slice interface{}) ISlice

ConcatM modifies this Slice by appending the given Slice using variadic expansion and returns a reference to this Slice. Supports InterSlice, *InterSlice, Slice and Go slice types

Example

ConcatM --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1).ConcatM([]int{2, 3})
fmt.Println(slice.O())
Output:

[1 2 3]

func (*InterSlice) Copy

func (p *InterSlice) Copy(indices ...int) (new ISlice)

Copy returns a new Slice with the indicated range of elements copied from this Slice. Expects nothing, in which case everything is copied, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.

Example

Copy --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Copy().O())
Output:

[1 2 3]

func (*InterSlice) Count

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

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

Example

Count --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 2)
fmt.Println(slice.Count(2))
Output:

2

func (*InterSlice) CountW

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

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

Example

CountW --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 2)
fmt.Println(slice.CountW(func(x O) bool {
	return ExB(x.(int) == 2)
}))
Output:

2

func (*InterSlice) Drop

func (p *InterSlice) Drop(indices ...int) ISlice

Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice. Expects nothing, in which case everything is dropped, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that DropAt(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

Example

Drop --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Drop(1, 1).O())
Output:

[1 3]

func (*InterSlice) DropAt

func (p *InterSlice) DropAt(i int) ISlice

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

Example

DropAt --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.DropAt(1).O())
Output:

[1 3]

func (*InterSlice) DropFirst

func (p *InterSlice) DropFirst() ISlice

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

Example

DropFirst --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.DropFirst().O())
Output:

[2 3]

func (*InterSlice) DropFirstN

func (p *InterSlice) DropFirstN(n int) ISlice

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

Example

DropFirstN --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.DropFirstN(2).O())
Output:

[3]

func (*InterSlice) DropLast

func (p *InterSlice) DropLast() ISlice

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

Example

DropLast --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.DropLast().O())
Output:

[1 2]

func (*InterSlice) DropLastN

func (p *InterSlice) DropLastN(n int) ISlice

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

Example

DropLastN --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.DropLastN(2).O())
Output:

[1]

func (*InterSlice) DropW

func (p *InterSlice) DropW(sel func(O) bool) ISlice

DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice. The slice is updated instantly when lambda expression is evaluated not after DropW completes.

Example

DropW --------------------------------------------------------------------------------------------------

slice := NewInterSliceV("1", "2", "3")
fmt.Println(slice.DropW(func(x O) bool {
	return ExB(Obj(x).ToInt()%2 == 0)
}).O())
Output:

[1 3]

func (*InterSlice) Each

func (p *InterSlice) Each(action func(O)) ISlice

Each calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice

Example

Each --------------------------------------------------------------------------------------------------

NewInterSliceV(1, 2, 3).Each(func(x O) {
	fmt.Printf("%v", x)
})
Output:

123

func (*InterSlice) EachE

func (p *InterSlice) EachE(action func(O) error) (ISlice, error)

EachE calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.

Example

EachE --------------------------------------------------------------------------------------------------

NewInterSliceV(1, 2, 3).EachE(func(x O) error {
	fmt.Printf("%v", x)
	return nil
})
Output:

123

func (*InterSlice) EachI

func (p *InterSlice) EachI(action func(int, O)) ISlice

EachI calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice

Example

EachI --------------------------------------------------------------------------------------------------

NewInterSliceV(1, 2, 3).EachI(func(i int, x O) {
	fmt.Printf("%v:%v", i, x)
})
Output:

0:11:22:3

func (*InterSlice) EachIE

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

EachIE calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice and any error from the lambda.

Example

EachIE --------------------------------------------------------------------------------------------------

NewInterSliceV(1, 2, 3).EachIE(func(i int, x O) error {
	fmt.Printf("%v:%v", i, x)
	return nil
})
Output:

0:11:22:3

func (*InterSlice) EachR

func (p *InterSlice) EachR(action func(O)) ISlice

EachR calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice

Example

EachR --------------------------------------------------------------------------------------------------

NewInterSliceV(1, 2, 3).EachR(func(x O) {
	fmt.Printf("%v", x)
})
Output:

321

func (*InterSlice) EachRE

func (p *InterSlice) EachRE(action func(O) error) (ISlice, error)

EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.

Example

EachRE --------------------------------------------------------------------------------------------------

NewInterSliceV(1, 2, 3).EachRE(func(x O) error {
	fmt.Printf("%v", x)
	return nil
})
Output:

321

func (*InterSlice) EachRI

func (p *InterSlice) EachRI(action func(int, O)) ISlice

EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice

Example

EachRI --------------------------------------------------------------------------------------------------

NewInterSliceV(1, 2, 3).EachRI(func(i int, x O) {
	fmt.Printf("%v:%v", i, x)
})
Output:

2:31:20:1

func (*InterSlice) EachRIE

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

EachRIE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.

Example

EachRIE --------------------------------------------------------------------------------------------------

NewInterSliceV(1, 2, 3).EachRIE(func(i int, x O) error {
	fmt.Printf("%v:%v", i, x)
	return nil
})
Output:

2:31:20:1

func (*InterSlice) Empty

func (p *InterSlice) Empty() bool

Empty tests if this Slice is empty.

Example

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

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

true

func (*InterSlice) First

func (p *InterSlice) First() (elem *Object)

First returns the first element in this Slice as Object. Object.Nil() == true will be returned when there are no elements in the slice.

Example

First --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.First().O())
Output:

1

func (*InterSlice) FirstN

func (p *InterSlice) FirstN(n int) ISlice

FirstN returns the first n elements in this slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.

Example

FirstN --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.FirstN(2).O())
Output:

[1 2]

func (*InterSlice) G

func (p *InterSlice) G() []interface{}

G returns the underlying Go type as is

func (*InterSlice) Index

func (p *InterSlice) Index(elem interface{}) (loc int)

Index returns the index of the first element in this Slice where element == elem Returns a -1 if the element was not not found.

Example

Index --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Index(2))
Output:

1

func (*InterSlice) Insert

func (p *InterSlice) Insert(i int, obj interface{}) ISlice

Insert modifies this Slice to insert the given element before the element with the given index. Negative indices count backwards from the end of the slice, where -1 is the last element. If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice. If a Slice is given all elements will be inserted starting from the beging until the end. Slice is returned for chaining. Invalid index locations will not change the slice.

Example

Insert --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 3)
fmt.Println(slice.Insert(1, 2).O())
Output:

[1 2 3]

func (*InterSlice) InterSlice

func (p *InterSlice) InterSlice() bool

InterSlice returns true if the underlying implementation is a RefSlice

Example

InterSlice --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.InterSlice())
Output:

true

func (*InterSlice) Join

func (p *InterSlice) Join(separator ...string) (str *Object)

Join converts each element into a string then joins them together using the given separator or comma by default.

Example

Join --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Join())
Output:

1,2,3

func (*InterSlice) Last

func (p *InterSlice) Last() (elem *Object)

Last returns the last element in this Slice as an Object. Object.Nil() == true will be returned if there are no elements in the slice.

Example

Last --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Last())
Output:

3

func (*InterSlice) LastN

func (p *InterSlice) LastN(n int) ISlice

LastN returns the last n elements in this Slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.

Example

LastN --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.LastN(2).O())
Output:

[2 3]

func (*InterSlice) Len

func (p *InterSlice) Len() int

Len returns the number of elements in this Slice

func (*InterSlice) Less

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

Less returns true if the element indexed by i is less than the element indexed by j. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.

Example

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

slice := NewInterSliceV(2, 3, 1)
fmt.Println(slice.Sort().O())
Output:

[1 2 3]

func (*InterSlice) Map

func (p *InterSlice) Map(mod func(O) O) ISlice

Map creates a new slice with the modified elements from the lambda.

Example

Map --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Map(func(x O) O { return x.(int) + 1 }).O())
Output:

[2 3 4]

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

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

Example

PopN --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.PopN(2))
Output:

[2 3]

func (*InterSlice) Prepend

func (p *InterSlice) Prepend(elem interface{}) ISlice

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

Example

Prepend --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(2, 3)
fmt.Println(slice.Prepend(1).O())
Output:

[1 2 3]

func (*InterSlice) RefSlice

func (p *InterSlice) RefSlice() bool

RefSlice returns true if the underlying implementation is a RefSlice

func (*InterSlice) Reverse

func (p *InterSlice) Reverse() (new ISlice)

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

Example

Reverse --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Reverse())
Output:

[3 2 1]

func (*InterSlice) ReverseM

func (p *InterSlice) ReverseM() ISlice

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

Example

ReverseM --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.ReverseM())
Output:

[3 2 1]

func (*InterSlice) S

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

S is an alias to ToStringSlice

func (*InterSlice) Select

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

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

Example

Select --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Select(func(x O) bool {
	return ExB(x.(int) == 2 || x.(int) == 3)
}))
Output:

[2 3]

func (*InterSlice) Set

func (p *InterSlice) Set(i int, elem interface{}) ISlice

Set the element at the given index location to the given element. Allows for negative notation. Returns a reference to this Slice and swallows any errors.

Example

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

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Set(0, 0).O())
Output:

[0 2 3]

func (*InterSlice) SetE

func (p *InterSlice) SetE(i int, elems interface{}) (ISlice, error)

SetE the element at the given index location to the given element. Allows for negative notation. Returns a referenc to this Slice and an error if out of bounds or elem is the wrong type.

Example

SetE --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.SetE(0, 0))
Output:

[0 2 3] <nil>

func (*InterSlice) Shift

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

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

Example

Shift --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Shift().O())
Output:

1

func (*InterSlice) ShiftN

func (p *InterSlice) ShiftN(n int) (new ISlice)

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

Example

ShiftN --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.ShiftN(2).O())
Output:

[1 2]

func (*InterSlice) Single

func (p *InterSlice) Single() bool

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

Example
slice := NewInterSliceV(1)
fmt.Println(slice.Single())
Output:

true

func (*InterSlice) Slice

func (p *InterSlice) Slice(indices ...int) ISlice

Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation. Expects nothing, in which case everything is included, or two indices i and j, in which case an inclusive behavior is used such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.

e.g. NewInterSliceV(1,2,3).Slice(0, -1) == [1,2,3] && NewInterSliceV(1,2,3).Slice(1,2) == [2,3]

Example

Slice --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Slice(1, -1).O())
Output:

[2 3]

func (*InterSlice) Sort

func (p *InterSlice) Sort() (new ISlice)

Sort returns a new Slice with sorted elements. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.

Example

Sort --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(2, 3, 1)
fmt.Println(slice.Sort())
Output:

[1 2 3]

func (*InterSlice) SortM

func (p *InterSlice) SortM() ISlice

SortM modifies this Slice sorting the elements and returns a reference to this Slice. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.

Example

SortM --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(2, 3, 1)
fmt.Println(slice.SortM())
Output:

[1 2 3]

func (*InterSlice) SortReverse

func (p *InterSlice) SortReverse() (new ISlice)

SortReverse returns a new Slice sorting the elements in reverse. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.

Example

SortReverse --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(2, 3, 1)
fmt.Println(slice.SortReverse())
Output:

[3 2 1]

func (*InterSlice) SortReverseM

func (p *InterSlice) SortReverseM() ISlice

SortReverseM modifies this Slice sorting the elements in reverse and returns a reference to this Slice. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.

Example

SortReverseM --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(2, 3, 1)
fmt.Println(slice.SortReverseM())
Output:

[3 2 1]

func (*InterSlice) String

func (p *InterSlice) String() string

Returns a string representation of this Slice, implements the Stringer interface

Example

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

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice)
Output:

[1 2 3]

func (*InterSlice) Swap

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

Swap modifies this Slice swapping the indicated elements.

Example

Swap --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(2, 3, 1)
slice.Swap(0, 2)
slice.Swap(1, 2)
fmt.Println(slice.O())
Output:

[1 2 3]

func (*InterSlice) Take

func (p *InterSlice) Take(indices ...int) (new ISlice)

Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice. Expects nothing, in which case everything is taken, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Take(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

Example

Take --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.Take(0, 1))
Output:

[1 2]

func (*InterSlice) TakeAt

func (p *InterSlice) TakeAt(i int) (elem *Object)

TakeAt modifies this Slice removing the elemement at the given index location and returns the removed element as an Object. Allows for negative notation.

Example

TakeAt --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.TakeAt(2).O())
Output:

3

func (*InterSlice) TakeW

func (p *InterSlice) TakeW(sel func(O) bool) (new ISlice)

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

Example

TakeW --------------------------------------------------------------------------------------------------

slice := NewInterSliceV(1, 2, 3)
fmt.Println(slice.TakeW(func(x O) bool {
	return ExB(x.(int)%2 == 0)
}))
Output:

[2]

func (*InterSlice) ToIntSlice

func (p *InterSlice) ToIntSlice() (slice *IntSlice)

ToIntSlice converts the underlying slice into a *IntSlice

func (*InterSlice) ToInterSlice

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

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

func (*InterSlice) ToInts

func (p *InterSlice) ToInts() (slice []int)

ToInts converts the underlying slice into a []int

func (*InterSlice) ToStringSlice

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

ToStringSlice converts the underlying slice into a *StringSlice

func (*InterSlice) ToStrs

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

ToStrs converts the underlying slice into a []string slice

func (*InterSlice) Union

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

Union returns a new Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports InterSlice, *InterSlice, Slice and Go slice types

func (*InterSlice) UnionM

func (p *InterSlice) UnionM(slice interface{}) ISlice

UnionM modifies this Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports InterSlice, *InterSlice, Slice and Go slice types

func (*InterSlice) Uniq

func (p *InterSlice) Uniq() (new ISlice)

Uniq returns a new Slice with all non uniq elements removed while preserving element order. Cost for this call vs the UniqM is roughly the same, this one is appending that one dropping.

func (*InterSlice) UniqM

func (p *InterSlice) UniqM() ISlice

UniqM modifies this Slice to remove all non uniq elements while preserving element order. Cost for this call vs the Uniq is roughly the same, this one is dropping that one appending.

type 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 providing a number of export methods for casting and converting to other types via the excellent cast package.

func Obj

func Obj(obj interface{}) *Object

Obj creates a new Object from the given obj appending the Object methods

func (*Object) 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) 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 converts an interface to a bool type.

func (*Object) ToBoolE

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

ToBoolE converts an interface to a bool type.

func (*Object) ToChar

func (p *Object) ToChar() *Char

ToChar converts an interface to a *Char type.

func (*Object) ToDuration

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

ToDuration converts an interface to a time.Duration type.

func (*Object) ToDurationE

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

ToDurationE converts an interface to a time.Duration type.

func (*Object) ToFloat32

func (p *Object) ToFloat32() float32

ToFloat32 converts an interface to a float32 type.

func (*Object) ToFloat32E

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

ToFloat32E converts 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 converts an interface to an int type.

func (*Object) ToInt16

func (p *Object) ToInt16() int16

ToInt16 converts an interface to an int16 type.

func (*Object) ToInt16E

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

ToInt16E converts an interface to an int16 type.

func (*Object) ToInt32

func (p *Object) ToInt32() int32

ToInt32 converts an interface to an int32 type.

func (*Object) ToInt32E

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

ToInt32E converts an interface to an int32 type.

func (*Object) ToInt64

func (p *Object) ToInt64() int64

ToInt64 converts an interface to an int64 type.

func (*Object) ToInt64E

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

ToInt64E converts an interface to an int64 type.

func (*Object) ToInt8

func (p *Object) ToInt8() int8

ToInt8 converts an interface to an int8 type.

func (*Object) ToInt8E

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

ToInt8E converts an interface to an int8 type.

func (*Object) ToIntE

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

ToIntE converts 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) ToRune

func (p *Object) ToRune() rune

ToRune converts an interface to a rune type.

func (*Object) ToSliceOfMap added in v1.2.1

func (p *Object) ToSliceOfMap() *SliceOfMap

ToSliceOfMap converts an interface to a *SliceOfMap type.

func (*Object) ToSliceOfMapE added in v1.2.1

func (p *Object) ToSliceOfMapE() (*SliceOfMap, error)

ToSliceOfMapE converts an interface to a *SliceOfMap type.

func (*Object) ToSliceOfMapG added in v1.2.1

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

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

func (*Object) ToSliceOfMapGE added in v1.2.1

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

ToSliceOfMapGE converts an interface to a []map[string]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 converts an interface to a string type.

func (*Object) ToStringE

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

ToStringE converts an interface to a string type.

func (*Object) ToStringMap

func (p *Object) ToStringMap() *StringMap

ToStringMap converts an interface to a *StringMap 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) 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) ToStrs

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

ToStrs converts an interface to a []string type.

func (*Object) ToStrsE

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

ToStrsE converts an interface to a []string type.

func (*Object) ToTime

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

ToTime converts an interface to a time.Time type.

func (*Object) ToTimeE

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

ToTimeE converts an interface to a time.Time type.

func (*Object) ToUint

func (p *Object) ToUint() uint

ToUint converts an interface to a uint type.

func (*Object) ToUint16

func (p *Object) ToUint16() uint16

ToUint16 converts an interface to a uint16 type.

func (*Object) ToUint16E

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

ToUint16E converts an interface to a uint16 type.

func (*Object) ToUint32

func (p *Object) ToUint32() uint32

ToUint32 converts an interface to a uint32 type.

func (*Object) ToUint32E

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

ToUint32E converts an interface to a uint32 type.

func (*Object) ToUint64

func (p *Object) ToUint64() uint64

ToUint64 converts an interface to a uint64 type.

func (*Object) ToUint64E

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

ToUint64E converts an interface to a uint64 type.

func (*Object) ToUint8

func (p *Object) ToUint8() uint8

ToUint8 converts an interface to a uint8 type.

func (*Object) ToUint8E

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

ToUint8E converts an interface to a uint8 type.

func (*Object) ToUintE

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

ToUintE converts 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) All added in v1.1.23

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

All tests if this Slice is not empty or optionally if it contains all of the given variadic elements; Incompatible types will return false.

func (*RefSlice) AllS added in v1.1.23

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

AllS tests if this Slice contains all of the given Slice's elements; Incompatible types will return false; Supports RefSlice, *RefSlice, Slice and Go slice types

func (*RefSlice) Any

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

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

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

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

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

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

Copy returns a new Slice with the indicated range of elements copied from this Slice. Expects nothing, in which case everything is copied, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.

Example
slice := 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) ISlice

Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice. Expects nothing, in which case everything is dropped, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that DropAt(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

Example
slice := NewRefSliceV(1, 2, 3)
fmt.Println(slice.Drop(1, 1).O())
Output:

[1 3]

func (*RefSlice) DropAt

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

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

Example
slice := NewRefSliceV(1, 2, 3)
fmt.Println(slice.DropAt(1))
Output:

[1 3]

func (*RefSlice) DropFirst

func (p *RefSlice) DropFirst() ISlice

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

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

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

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

DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice. The slice is updated instantly when lambda expression is evaluated not after DropW completes.

func (*RefSlice) Each

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

Each calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice

Example
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) (ISlice, error)

EachE calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.

Example
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)) ISlice

EachI calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice

Example
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) (ISlice, 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)) ISlice

EachR calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice

Example
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) (ISlice, error)

EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.

Example
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)) ISlice

EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice

Example
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) (ISlice, 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) ISlice

FirstN returns the first n elements in this slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.

Example
slice := 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{}) ISlice

Insert modifies this Slice to insert the given element before the element with the given index. Negative indices count backwards from the end of the slice, where -1 is the last element. If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice. If a Slice is given all elements will be inserted starting from the beging until the end. Slice is returned for chaining. Invalid index locations will not change the slice.

Example
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{}) ISlice

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

LastN returns the last n elements in this Slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.

Example
slice := 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) Map

func (p *RefSlice) Map(mod func(O) O) ISlice

Map creates a new slice with the modified elements from the lambda.

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

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

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

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

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

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

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

Set the element at the given index location to the given element. Allows for negative notation. Returns a reference to this Slice and swallows any errors.

Example
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{}) (ISlice, error)

SetE the element at the given index location to the given element. Allows for negative notation. Returns a referenc to this Slice and an error if out of bounds or elem is the wrong type.

Example
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 ISlice)

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

Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation. Expects nothing, in which case everything is included, or two indices i and j, in which case an inclusive behavior is used such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.

e.g. 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 ISlice)

Sort returns a new Slice with sorted elements. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.

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

[1 2 3]

func (*RefSlice) SortM

func (p *RefSlice) SortM() ISlice

SortM modifies this Slice sorting the elements and returns a reference to this Slice. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.

Example
slice := NewRefSliceV(2, 3, 1)
fmt.Println(slice.SortM())
Output:

[1 2 3]

func (*RefSlice) SortReverse

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

SortReverse returns a new Slice sorting the elements in reverse. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.

Example
slice := NewRefSliceV(2, 3, 1)
fmt.Println(slice.SortReverse())
Output:

[3 2 1]

func (*RefSlice) SortReverseM

func (p *RefSlice) SortReverseM() ISlice

SortReverseM modifies this Slice sorting the elements in reverse and returns a reference to this Slice. Supports optimized Slice types or Go types that can be converted into an optimized Slice type.

Example
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 ISlice)

Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice. Expects nothing, in which case everything is taken, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Take(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

Example
slice := 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 ISlice)

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

Example
slice := NewRefSliceV(1, 2, 3)
fmt.Println(slice.TakeW(func(x O) bool {
	return ExB(x.(int)%2 == 0)
}))
Output:

[2]

func (*RefSlice) ToIntSlice

func (p *RefSlice) ToIntSlice() (slice *IntSlice)

ToIntSlice converts the underlying slice into a *IntSlice

func (*RefSlice) ToInterSlice

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

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

func (*RefSlice) ToInts

func (p *RefSlice) ToInts() (slice []int)

ToInts converts the underlying slice into a []int

func (*RefSlice) ToStringSlice

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

ToStringSlice converts the underlying slice into a *StringSlice

func (*RefSlice) ToStrs

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

ToStrs converts the underlying slice into a []string slice

func (*RefSlice) Union

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

Union returns a new Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports RefSlice, *RefSlice, Slice and Go slice types

func (*RefSlice) UnionM

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

UnionM modifies this Slice by joining uniq elements from this Slice with uniq elements from the given Slice while preserving order. Supports RefSlice, *RefSlice, Slice and Go slice types

func (*RefSlice) Uniq

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

Uniq returns a new Slice with all non uniq elements removed while preserving element order. Cost for this call vs the UniqM is roughly the same, this one is appending that one dropping.

Example
slice := NewRefSliceV(1, 2, 3, 3)
fmt.Println(slice.Uniq())
Output:

[1 2 3]

func (*RefSlice) UniqM

func (p *RefSlice) UniqM() ISlice

UniqM modifies this Slice to remove all non uniq elements while preserving element order. Cost for this call vs the Uniq is roughly the same, this one is dropping that one appending.

Example
slice := 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 SliceOfMap added in v1.2.1

type SliceOfMap []*StringMap

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

func NewSliceOfMap added in v1.2.1

func NewSliceOfMap(slice interface{}) *SliceOfMap

NewSliceOfMap creates a new *SliceOfMap

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

[&[{foo bar}]]

func NewSliceOfMapV added in v1.2.1

func NewSliceOfMapV(obj ...interface{}) *SliceOfMap

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

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

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

[&[{foo1 1}] &[{foo2 2}]]

func ToSliceOfMap added in v1.2.1

func ToSliceOfMap(obj interface{}) *SliceOfMap

ToSliceOfMap converts an interface to a SliceOfMap type.

func ToSliceOfMapE added in v1.2.1

func ToSliceOfMapE(obj interface{}) (val *SliceOfMap, err error)

ToSliceOfMapE converts an interface to a SliceOfMap type.

Example

ToSliceOfMapE --------------------------------------------------------------------------------------------------

fmt.Println(ToSliceOfMapE([]map[interface{}]interface{}{{"1": "one"}}))
Output:

[&[{1 one}]] <nil>

func (*SliceOfMap) A added in v1.2.1

func (p *SliceOfMap) A() string

A is an alias to String for brevity

func (*SliceOfMap) All added in v1.2.1

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

All tests if this Slice is not empty or optionally if it contains all of the given variadic elements. Incompatible types will return false.

func (*SliceOfMap) AllS added in v1.2.1

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

AllS tests if this Slice contains all of the given Slice's elements; Incompatible types will return false; Supports SliceOfMap, *SliceOfMap, []string or *[]string

func (*SliceOfMap) Any added in v1.2.1

func (p *SliceOfMap) Any(elems ...interface{}) bool

Any tests if this Slice is not empty or optionally if it contains any of the given variadic elements. Incompatible types will return false.

Example (Contains)
slice := NewSliceOfMapV("1:", "2:", "3:")
fmt.Println(slice.Any("1"))
Output:

true
Example (ContainsAny)
slice := NewSliceOfMapV("1:", "2:", "3:")
fmt.Println(slice.Any("0", "1"))
Output:

true
Example (Empty)
slice := NewSliceOfMapV()
fmt.Println(slice.Any())
Output:

false
Example (NotEmpty)
slice := NewSliceOfMapV("1:", "2:", "3:")
fmt.Println(slice.Any())
Output:

true

func (*SliceOfMap) AnyS added in v1.2.1

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

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

Example
slice := NewSliceOfMapV("1:", "2:", "3:")
fmt.Println(slice.AnyS([]string{"0", "1"}))
Output:

true

func (*SliceOfMap) AnyW added in v1.2.1

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

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

func (*SliceOfMap) Append added in v1.2.1

func (p *SliceOfMap) Append(elem interface{}) ISlice

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

func (*SliceOfMap) AppendV added in v1.2.1

func (p *SliceOfMap) AppendV(elems ...interface{}) ISlice

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

Example
slice := NewSliceOfMapV("1:").AppendV("2:", "3:")
fmt.Println(slice)
Output:

[&[{1 <nil>}] &[{2 <nil>}] &[{3 <nil>}]]

func (*SliceOfMap) At added in v1.2.1

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

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

Example
slice := NewSliceOfMapV("1:", "2:", "3:")
fmt.Println(slice.At(2))
Output:

&[{3 <nil>}]

func (*SliceOfMap) Clear added in v1.2.1

func (p *SliceOfMap) Clear() ISlice

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

Example

Clear --------------------------------------------------------------------------------------------------

slice := NewSliceOfMapV("1:").Concat([]string{"2", "3"})
fmt.Println(slice.Clear())
Output:

[]

func (*SliceOfMap) Concat added in v1.2.1

func (p *SliceOfMap) Concat(slice interface{}) (new ISlice)

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

Example
slice := NewSliceOfMapV("1:").Concat([]interface{}{"2:", "3:"})
fmt.Println(slice)
Output:

[&[{1 <nil>}] &[{2 <nil>}] &[{3 <nil>}]]

func (*SliceOfMap) ConcatM added in v1.2.1

func (p *SliceOfMap) ConcatM(slice interface{}) ISlice

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

Example
slice := NewSliceOfMapV("1:").ConcatM([]interface{}{"2:", "3:"})
fmt.Println(slice)
Output:

[&[{1 <nil>}] &[{2 <nil>}] &[{3 <nil>}]]

func (*SliceOfMap) Copy added in v1.2.1

func (p *SliceOfMap) Copy(indices ...int) (new ISlice)

Copy returns a new Slice with the indicated range of elements copied from this Slice. Expects nothing, in which case everything is copied, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.

Example
slice := NewSliceOfMapV("1:", "2:", "3:")
fmt.Println(slice.Copy())
Output:

[&[{1 <nil>}] &[{2 <nil>}] &[{3 <nil>}]]

func (*SliceOfMap) Count added in v1.2.1

func (p *SliceOfMap) Count(key interface{}) (cnt int)

Count the number of elements in this Slice that contain the given key

Example
slice := NewSliceOfMapV("1:", "2:", "2:")
fmt.Println(slice.Count("2"))
Output:

2

func (*SliceOfMap) CountW added in v1.2.1

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

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

Example
slice := NewSliceOfMapV("1:", "2:", "2:")
fmt.Println(slice.CountW(func(x O) bool {
	return ToStringMap(x).Exists("2")
}))
Output:

2

func (*SliceOfMap) Drop added in v1.2.1

func (p *SliceOfMap) Drop(indices ...int) ISlice

Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice. Expects nothing, in which case everything is dropped, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that DropAt(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

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

[&[{3 <nil>}]]

func (*SliceOfMap) DropAt added in v1.2.1

func (p *SliceOfMap) DropAt(i int) ISlice

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

Example
slice := NewSliceOfMapV("1:", "2:", "3:")
fmt.Println(slice.DropAt(1))
Output:

[&[{1 <nil>}] &[{3 <nil>}]]

func (*SliceOfMap) DropFirst added in v1.2.1

func (p *SliceOfMap) DropFirst() ISlice

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

Example
slice := NewSliceOfMapV("1:", "2:", "3:")
fmt.Println(slice.DropFirst())
Output:

[&[{2 <nil>}] &[{3 <nil>}]]

func (*SliceOfMap) DropFirstN added in v1.2.1

func (p *SliceOfMap) DropFirstN(n int) ISlice

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

Example
slice := NewSliceOfMapV("1:", "2:", "3:")
fmt.Println(slice.DropFirstN(2))
Output:

[&[{3 <nil>}]]

func (*SliceOfMap) DropLast added in v1.2.1

func (p *SliceOfMap) DropLast() ISlice

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

Example
slice := NewSliceOfMapV("1:", "2:", "3:")
fmt.Println(slice.DropLast())
Output:

[&[{1 <nil>}] &[{2 <nil>}]]

func (*SliceOfMap) DropLastN added in v1.2.1

func (p *SliceOfMap) DropLastN(n int) ISlice

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

Example
slice := NewSliceOfMapV("1:", "2:", "3:")
fmt.Println(slice.DropLastN(2))
Output:

[&[{1 <nil>}]]

func (*SliceOfMap) DropW added in v1.2.1

func (p *SliceOfMap) DropW(sel func(O) bool) ISlice

DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice. The slice is updated instantly when lambda expression is evaluated not after DropW completes.

Example
slice := NewSliceOfMapV("1:", "2:", "3:")
fmt.Println(slice.DropW(func(x O) bool {
	return ToStringMap(x).Exists("2")
}))
Output:

[&[{1 <nil>}] &[{3 <nil>}]]

func (*SliceOfMap) Each added in v1.2.1

func (p *SliceOfMap) Each(action func(O)) ISlice

Each calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice

Example
NewSliceOfMapV([]map[string]interface{}{{"foo": "bar"}}).Each(func(x O) {
	fmt.Printf("%v", x)
})
Output:

&[{foo bar}]

func (*SliceOfMap) EachE added in v1.2.1

func (p *SliceOfMap) EachE(action func(O) error) (ISlice, error)

EachE calls the given lambda once for each element in this Slice, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.

Example
NewSliceOfMapV([]map[string]interface{}{{"foo": "bar"}}).EachE(func(x O) error {
	fmt.Printf("%v", x)
	return nil
})
Output:

&[{foo bar}]

func (*SliceOfMap) EachI added in v1.2.1

func (p *SliceOfMap) EachI(action func(int, O)) ISlice

EachI calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice

Example
NewSliceOfMapV("1:", "2:", "3:").EachI(func(i int, x O) {
	fmt.Printf("%v %v", i, x)
})
Output:

0 &[{1 <nil>}]1 &[{2 <nil>}]2 &[{3 <nil>}]

func (*SliceOfMap) EachIE added in v1.2.1

func (p *SliceOfMap) EachIE(action func(int, O) error) (ISlice, error)

EachIE calls the given lambda once for each element in this Slice, passing in the index and element as a parameter. Returns a reference to this Slice and any error from the lambda.

func (*SliceOfMap) EachR added in v1.2.1

func (p *SliceOfMap) EachR(action func(O)) ISlice

EachR calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice

func (*SliceOfMap) EachRE added in v1.2.1

func (p *SliceOfMap) EachRE(action func(O) error) (ISlice, error)

EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.

func (*SliceOfMap) EachRI added in v1.2.1

func (p *SliceOfMap) EachRI(action func(int, O)) ISlice

EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice

func (*SliceOfMap) EachRIE added in v1.2.1

func (p *SliceOfMap) EachRIE(action func(int, O) error) (ISlice, error)

EachRIE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter. Returns a reference to this Slice and any error from the lambda.

func (*SliceOfMap) Empty added in v1.2.1

func (p *SliceOfMap) Empty() bool

Empty tests if this Slice is empty.

Example

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

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

true

func (*SliceOfMap) First added in v1.2.1

func (p *SliceOfMap) First() (elem *Object)

First returns the first element in this Slice as Object. Object.Nil() == true will be returned when there are no elements in the slice.

func (*SliceOfMap) FirstN added in v1.2.1

func (p *SliceOfMap) FirstN(n int) ISlice

FirstN returns the first n elements in this slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.

func (*SliceOfMap) G added in v1.2.1

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

G returns the underlying data structure as a builtin Go type

func (*SliceOfMap) Index added in v1.2.1

func (p *SliceOfMap) Index(elem interface{}) (loc int)

Index returns the index of the first element in this Slice where element == elem Returns a -1 if the element was not not found.

func (*SliceOfMap) Insert added in v1.2.1

func (p *SliceOfMap) Insert(i int, obj interface{}) ISlice

Insert modifies this Slice to insert the given elements before the element(s) with the given index. Negative indices count backwards from the end of the slice, where -1 is the last element. If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice. If a Slice is given all elements will be inserted starting from the beging until the end. Slice is returned for chaining. Invalid index locations will not change the slice.

func (*SliceOfMap) InterSlice added in v1.2.1

func (p *SliceOfMap) InterSlice() bool

InterSlice returns true if the underlying implementation is a RefSlice

func (*SliceOfMap) Join added in v1.2.1

func (p *SliceOfMap) Join(separator ...string) (str *Object)

Join converts each element into a string then joins them together using the given separator or comma by default.

func (*SliceOfMap) Last added in v1.2.1

func (p *SliceOfMap) Last() (elem *Object)

Last returns the last element in this Slice as an Object. Object.Nil() == true will be returned if there are no elements in the slice.

func (*SliceOfMap) LastN added in v1.2.1

func (p *SliceOfMap) LastN(n int) ISlice

LastN returns the last n elements in this Slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.

func (*SliceOfMap) Len added in v1.2.1

func (p *SliceOfMap) Len() int

Len returns the number of elements in this Slice

func (*SliceOfMap) Less added in v1.2.1

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

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

func (*SliceOfMap) Map added in v1.2.1

func (p *SliceOfMap) Map(mod func(O) O) ISlice

Map creates a new slice with the modified elements from the lambda.

func (*SliceOfMap) Nil added in v1.2.1

func (p *SliceOfMap) Nil() bool

Nil tests if this Slice is nil

func (*SliceOfMap) O added in v1.2.1

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

O returns the underlying data structure as is

func (*SliceOfMap) Pair added in v1.2.1

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

Pair simply returns the first and second Slice elements as Objects

func (*SliceOfMap) Pop added in v1.2.1

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

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

func (*SliceOfMap) PopN added in v1.2.1

func (p *SliceOfMap) PopN(n int) (new ISlice)

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

func (*SliceOfMap) Prepend added in v1.2.1

func (p *SliceOfMap) Prepend(elem interface{}) ISlice

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

func (*SliceOfMap) RefSlice added in v1.2.1

func (p *SliceOfMap) RefSlice() bool

RefSlice returns true if the underlying implementation is a RefSlice

func (*SliceOfMap) Reverse added in v1.2.1

func (p *SliceOfMap) Reverse() (new ISlice)

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

func (*SliceOfMap) ReverseM added in v1.2.1

func (p *SliceOfMap) ReverseM() ISlice

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

func (*SliceOfMap) S added in v1.2.1

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

S is an alias to ToStringSlice

func (*SliceOfMap) Select added in v1.2.1

func (p *SliceOfMap) Select(sel func(O) bool) (new ISlice)

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

func (*SliceOfMap) Set added in v1.2.1

func (p *SliceOfMap) Set(i int, elem interface{}) ISlice

Set the element at the given index location to the given element. Allows for negative notation. Returns a reference to this Slice and swallows any errors.

func (*SliceOfMap) SetE added in v1.2.1

func (p *SliceOfMap) SetE(i int, elems interface{}) (slice ISlice, err error)

SetE the element at the given index location to the given element. Allows for negative notation. Returns a referenc to this Slice and an error if out of bounds or elem is the wrong type.

func (*SliceOfMap) Shift added in v1.2.1

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

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

func (*SliceOfMap) ShiftN added in v1.2.1

func (p *SliceOfMap) ShiftN(n int) (new ISlice)

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

func (*SliceOfMap) Single added in v1.2.1

func (p *SliceOfMap) Single() bool

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

func (*SliceOfMap) Slice added in v1.2.1

func (p *SliceOfMap) Slice(indices ...int) ISlice

Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation. Expects nothing, in which case everything is included, or two indices i and j, in which case an inclusive behavior is used such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.

e.g. NewSliceOfMapV(1,2,3).Slice(0, -1) == [1,2,3] && NewSliceOfMapV(1,2,3).Slice(1,2) == [2,3]

func (*SliceOfMap) Sort added in v1.2.1

func (p *SliceOfMap) Sort() (new ISlice)

Sort returns a new Slice with sorted elements.

func (*SliceOfMap) SortM added in v1.2.1

func (p *SliceOfMap) SortM() ISlice

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

func (*SliceOfMap) SortReverse added in v1.2.1

func (p *SliceOfMap) SortReverse() (new ISlice)

SortReverse returns a new Slice sorting the elements in reverse.

func (*SliceOfMap) SortReverseM added in v1.2.1

func (p *SliceOfMap) SortReverseM() ISlice

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

func (*SliceOfMap) String added in v1.2.1

func (p *SliceOfMap) String() string

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

func (*SliceOfMap) Swap added in v1.2.1

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

Swap modifies this Slice swapping the indicated elements.

func (*SliceOfMap) Take added in v1.2.1

func (p *SliceOfMap) Take(indices ...int) (new ISlice)

Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice. Expects nothing, in which case everything is taken, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Take(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

func (*SliceOfMap) TakeAt added in v1.2.1

func (p *SliceOfMap) TakeAt(i int) (elem *Object)

TakeAt modifies this Slice removing the elemement at the given index location and returns the removed element as an Object. Allows for negative notation.

func (*SliceOfMap) TakeW added in v1.2.1

func (p *SliceOfMap) TakeW(sel func(O) bool) (new ISlice)

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

func (*SliceOfMap) ToIntSlice added in v1.2.1

func (p *SliceOfMap) ToIntSlice() (slice *IntSlice)

ToIntSlice converts the underlying slice into a *IntSlice

func (*SliceOfMap) ToInterSlice added in v1.2.1

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

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

func (*SliceOfMap) ToInts added in v1.2.1

func (p *SliceOfMap) ToInts() (slice []int)

ToInts converts the underlying slice into a []int

func (*SliceOfMap) ToStringSlice added in v1.2.1

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

ToStringSlice converts the underlying slice into a *StringSlice

func (*SliceOfMap) ToStrs added in v1.2.1

func (p *SliceOfMap) ToStrs() (slice []string)

ToStrs converts the underlying slice into a []string slice

func (*SliceOfMap) Union added in v1.2.1

func (p *SliceOfMap) Union(slice interface{}) (new ISlice)

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

func (*SliceOfMap) UnionM added in v1.2.1

func (p *SliceOfMap) UnionM(slice interface{}) ISlice

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

func (*SliceOfMap) Uniq added in v1.2.1

func (p *SliceOfMap) Uniq() (new ISlice)

Uniq returns a new Slice with all non uniq elements removed while preserving element order. Cost for this call vs the UniqM is roughly the same, this one is appending that one dropping.

func (*SliceOfMap) UniqM added in v1.2.1

func (p *SliceOfMap) UniqM() ISlice

UniqM modifies this Slice to remove all non uniq elements while preserving element order. Cost for this call vs the Uniq is roughly the same, this one is dropping that one appending.

type Str

type Str []rune

Str wraps the Go []rune and implements the Slice interface providing convenience methods on par with rapid development languages.

func A

func A(obj interface{}) *Str

A is an alias to ToStr for brevity

Example

A --------------------------------------------------------------------------------------------------

str := A("test")
fmt.Println(str)
Output:

test

func NewStr

func NewStr(obj interface{}) *Str

NewStr creates a new *Str which will never be nil Supports: Str *Str, string *string, []byte *[]byte, rune *rune, []rune *[]rune, []string *[]string ...

Example

NewStr --------------------------------------------------------------------------------------------------

str := NewStr("test")
fmt.Println(str)
Output:

test

func NewStrV

func NewStrV(elems ...interface{}) *Str

NewStrV creates a new *Str from the given variadic elements. Returned *Str will never be nil. Supports: Str *Str, string *string, []byte *[]byte, rune *rune, []rune *[]rune, []string *[]string ...

func ToStr

func ToStr(obj interface{}) *Str

ToStr convert an interface to a *Str type.

Example

ToStr --------------------------------------------------------------------------------------------------

val := ToStr(true)
fmt.Println(val)
Output:

true

func (*Str) 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{}) ISlice

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

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

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

Example

Clear --------------------------------------------------------------------------------------------------

slice := NewStrV("1").Concat([]string{"2", "3"})
fmt.Println(slice.Clear())
Output:

func (*Str) Concat

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

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

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

Copy returns a new Slice with the indicated range of elements copied from this Slice. Expects nothing, in which case everything is copied, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.

Example
slice := 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) ISlice

Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice. Expects nothing, in which case everything is dropped, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that DropAt(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

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

3

func (*Str) DropAt

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

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

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

13

func (*Str) DropFirst

func (p *Str) DropFirst() ISlice

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

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

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

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

DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice. The slice is updated instantly when lambda expression is evaluated not after DropW completes.

Example
slice := 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)) ISlice

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

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

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

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

FirstN returns the first n elements in this slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.

Example
slice := 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{}) ISlice

Insert modifies this Slice to insert the given element before the element with the given index. Negative indices count backwards from the end of the slice, where -1 is the last element. If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice. 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) ISlice

LastN returns the last n elements in this Slice as a Slice reference to the original. Best effort is used such that as many as can be will be returned up until the request is satisfied.

Example
slice := 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

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

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

false

func (*Str) Map

func (p *Str) Map(mod func(O) O) ISlice

Map creates a new slice with the modified elements from the lambda.

Example

Map --------------------------------------------------------------------------------------------------

slice := NewStrV("1", "2", "3").Map(func(x O) O {
	return x.(rune) + 1
})
fmt.Println(slice.O())
Output:

234

func (*Str) Nil

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

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

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

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

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

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

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

Set the element(s) at the given index location to the given element(s). Allows for negative notation. Returns a reference to this Slice and swallows any errors.

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

023

func (*Str) SetE

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

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

Slice returns a range of elements from this Slice as a Slice reference to the original. Allows for negative notation. Expects nothing, in which case everything is included, or two indices i and j, in which case an inclusive behavior is used such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.

e.g. 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 ISlice)

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

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

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

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

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

321

func (*Str) Split

func (p *Str) Split(separator ...string) (slice *StringSlice)

Split this Str into all substrings delimited by separator and returns a slice of the substrings. If Str does not contain separator, Split returns a slice of length 1 whose only element is Str. If Str is empty, Split returns an empty slice. separator defaults to comma if not given.

Example
slice := NewStr("1,2,3")
fmt.Println(slice.Split())
Output:

[1 2 3]

func (*Str) SplitAfter

func (p *Str) SplitAfter(separator ...string) (slice *StringSlice)

SplitAfter splits this Str into all substrings deliniated by separator and returns a slice of the substrings. If Str does not contain separator, Split returns a slice of length 1 whose only element is Str. If Str is empty, Split returns an empty slice. separator defaults to comma if not given.

Example
slice := NewStr("1,2,3")
fmt.Println(slice.SplitAfter())
Output:

[1, 2, 3]

func (*Str) SplitEscape added in v1.2.9

func (p *Str) SplitEscape(separator string, escape ...string) (slice *StringSlice)

SplitEscape wraps the Split function handling a possible escape string. When given the escape character will cause the split to be ignored and the escape string to be stripped out

Example
slice := NewStr("1,2,3")
fmt.Println(slice.SplitEscape(","))
Output:

[1 2 3]

func (*Str) SplitQuotes

func (p *Str) SplitQuotes() (slice *StringSlice, err error)

SplitQuotes splits this Str into substrings starting and ending with double quotes and returns a slice of the substrings. If Str does not contain quotes, Split returns a slice of length 1 whose only element is Str. If Str is empty, Split returns an empty slice. Unmatched quotes throw and error and empty quotes are removed.

Example

SplitQuotes --------------------------------------------------------------------------------------------------

slice := NewStr(`."foo.bar"`)
fmt.Println(slice.SplitQuotes())
Output:

[. "foo.bar"] <nil>

func (*Str) String

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

Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice. Expects nothing, in which case everything is taken, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Take(0, -1) includes index -1 as opposed to Go's exclusive behavior. Out of bounds indices will be moved within bounds.

Example
slice := 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 ISlice)

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

func (p *Str) ToIntSlice() (slice *IntSlice)

ToIntSlice converts the underlying slice into a *IntSlice

func (*Str) ToInterSlice

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

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

func (*Str) ToInts

func (p *Str) ToInts() (slice []int)

ToInts converts the underlying slice into a []int

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

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

ToStrs 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 ISlice)

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

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

Uniq returns a new Slice with all non uniq elements removed while preserving element order. Cost for this call vs the UniqM is roughly the same, this one is appending that one dropping.

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

123

func (*Str) UniqM

func (p *Str) UniqM() ISlice

UniqM modifies this Slice to remove all non uniq elements while preserving element order. Cost for this call vs the Uniq is roughly the same, this one is dropping that one appending.

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

123

type StringMap

type StringMap yaml.MapSlice

StringMap implements the IMap interface providing a generic way to work with map types including convenience methods on par with rapid development languages. This type is also specifically designed to handle ordered YAML constructs to work with YAML files with minimal structural changes i.e. no mass sorting changes.

func LoadJSON

func LoadJSON(filepath string) (m *StringMap)

LoadJSON reads in a json file and converts it to a *StringMap

func LoadJSONE

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

LoadJSONE reads in a json file and converts it to a *StringMap

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

M is an alias to NewStringMap

func MV

func MV(m ...interface{}) *StringMap

MV is an alias to NewStringMapV

func Map

func Map(obj interface{}) (new *StringMap)

Map provides a generic way to work with Map types. It does this by wrapping Go types directly for optimized types thus avoiding reflection processing overhead and making a plethora of Map methods available. Non-optimized types will fall back on reflection to generically handle the type incurring the full 10x reflection processing overhead.

Optimized: map[string]interface{}

Example

Map --------------------------------------------------------------------------------------------------

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

&[{k v}]

func NewStringMap

func NewStringMap(obj interface{}) *StringMap

NewStringMap converts the given interface{} into a StringMap

Example

NewStringMap --------------------------------------------------------------------------------------------------

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

&[{k v}]

func NewStringMapV

func NewStringMapV(m ...interface{}) *StringMap

NewStringMapV creates a new empty StringMap if nothing given else converts the given value into a StringMap.

Example

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

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

&[{k v}]

func ToStringMap

func ToStringMap(obj interface{}) *StringMap

ToStringMap converts an interface to a StringMap type. Supports converting yaml string as well.

func ToStringMapE

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:

&[{1 one}] <nil>

func (*StringMap) Add added in v1.2.0

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

Add the value to the map if it doesn't exist or update value if it does

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) At added in v1.2.1

func (p *StringMap) At(i int) (key string, val *Object)

At gets the key value pair for the given index location

func (*StringMap) Clear

func (p *StringMap) Clear() IMap

Clear modifies this Map to clear out all key-value pairs and returns a reference to this Map.

Example

Clear --------------------------------------------------------------------------------------------------

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

&[]

func (*StringMap) Copy

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

Copy returns a new Map with the indicated key-value pairs copied from this Map or all if not given.

Example

Copy --------------------------------------------------------------------------------------------------

m := NewStringMapV(map[string]interface{}{"1": "one", "2": "two"})
fmt.Println(m.Copy("1"))
Output:

&[{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{}) IMap

DeleteM modifies this Map to delete the indicated key-value pair and returns a reference to this Map rather than the key-value pair.

Example

DeleteM --------------------------------------------------------------------------------------------------

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

&[]

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) GE added in v1.2.0

func (p *StringMap) GE() (val map[string]interface{}, err error)

GE 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) Keys

func (p *StringMap) Keys() ISlice

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

Example

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

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

[1]

func (*StringMap) Len

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 IMap, selector ...string) IMap

Merge modifies this Map by overriding its values at selector with the given map where they both exist and returns a reference to this Map. Converting all string maps into *StringMap instances. Note: this function is unable to traverse through lists

Example

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

fmt.Println(M().Add("1", "two").Merge(M().Add("1", "one")))
Output:

&[{1 one}]

func (*StringMap) MergeG

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

Merge modifies this Map by overriding its values at selector with the given map where they both exist and returns a reference to this Map. Converting all string maps into *StringMap instances. Note: this function is unable to traverse through lists

Example

MergeG --------------------------------------------------------------------------------------------------

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

map[1:one]

func (*StringMap) O

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

O returns the underlying data structure as is.

Example

O --------------------------------------------------------------------------------------------------

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

map[1:one]

func (*StringMap) Query

func (p *StringMap) Query(selector string, params ...interface{}) (val *Object)

Query returns the value for the given selector, using jq type selectors. Returns empty *Object if not found.

  • `selector` supports dot notation similar to https://stedolan.github.io/jq/manual/#Basicfilters with some caveats
  • `params` are the string interpolation paramaters similar to fmt.Sprintf()
  • use the \\ character to escape periods that don't separate keys e.g. "[version=1\\.2\\.3]"
Example

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

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

1

func (*StringMap) QueryE

func (p *StringMap) QueryE(selector string, params ...interface{}) (val *Object, err error)

QueryE returns the value for the given selector, using jq type selectors. Returns empty *Object if not found.

  • `selector` supports dot notation similar to https://stedolan.github.io/jq/manual/#Basicfilters with some caveats
  • `params` are the string interpolation paramaters similar to fmt.Sprintf()
  • use the \\ character to escape periods that don't separate keys e.g. "[version=1\\.2\\.3]"

func (*StringMap) Remove

func (p *StringMap) Remove(selector string, params ...interface{}) IMap

Remove modifies this Map to delete the given key location, using jq type selectors and returns a reference to this Map rather than the deleted value.

  • `selector` supports dot notation similar to https://stedolan.github.io/jq/manual/#Basicfilters with some caveats
  • `params` are the string interpolation paramaters similar to fmt.Sprintf()
  • use the \\ character to escape periods that don't separate keys e.g. "[version=1\\.2\\.3]"
Example

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

fmt.Println(ToStringMap("foo:\n  bar1: 1\n  bar2: 2\n").Remove("foo.bar1"))
Output:

&[{foo [{bar2 2}]}]

func (*StringMap) RemoveE

func (p *StringMap) RemoveE(selector string, params ...interface{}) (m IMap, 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.

  • `selector` supports dot notation similar to https://stedolan.github.io/jq/manual/#Basicfilters with some caveats
  • `params` are the string interpolation paramaters similar to fmt.Sprintf()
  • use the \\ character to escape periods that don't separate keys e.g. "[version=1\\.2\\.3]"

func (*StringMap) Set

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 exist in this Map.

Example

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

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

true

func (*StringMap) SetM

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

SetM the value for the given key to the given val creating map if necessary. Returns a reference to this Map.

Example

SetM --------------------------------------------------------------------------------------------------

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

&[{k v}]

func (*StringMap) ToStringMap

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) Update added in v1.2.0

func (p *StringMap) Update(selector string, val interface{}) IMap

Update sets the value for the given selector, using jq type selectors. Returns a reference to this Map.

Example

Update --------------------------------------------------------------------------------------------------

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

&[{1 one}]

func (*StringMap) UpdateE added in v1.2.0

func (p *StringMap) UpdateE(selector string, val interface{}) (m IMap, err error)

UpdateE sets the value for the given selector, using jq type selectors. Returns a reference to this Map.

func (*StringMap) WriteJSON

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

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

func (*StringMap) WriteYAML

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

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

func (*StringMap) YAML added in v1.1.6

func (p *StringMap) YAML() (data string)

YAML converts the Map into a YAML string

func (*StringMap) YAMLE added in v1.1.7

func (p *StringMap) YAMLE() (data string, err error)

YAMLE converts the Map into a YAML string

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, params ...interface{}) (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) All added in v1.1.23

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

All tests if this Slice contains all the given variadic elements; Incompatible types will return false.

Example (Contains)
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.All("1"))
Output:

true
Example (ContainsAll)
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.All("3", "1"))
Output:

true
Example (Empty)

All --------------------------------------------------------------------------------------------------

slice := NewStringSliceV()
fmt.Println(slice.All())
Output:

false
Example (NotEmpty)
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.All())
Output:

true

func (*StringSlice) AllS added in v1.1.23

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

AllS tests if this Slice contains all of the given Slice's elements; Incompatible types will return false; Supports StringSlice, *StringSlice, []string or *[]string

Example

AllS --------------------------------------------------------------------------------------------------

slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.AllS([]string{"2", "1"}))
Output:

true

func (*StringSlice) Any

func (p *StringSlice) Any(elems ...interface{}) bool

Any tests if this Slice is not empty or optionally if it contains any of the given variadic elements; Incompatible types will return false.

Example (Contains)
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.Any("1"))
Output:

true
Example (ContainsAny)
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.Any("0", "1"))
Output:

true
Example (Empty)
slice := NewStringSliceV()
fmt.Println(slice.Any())
Output:

false
Example (NotEmpty)
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.Any())
Output:

true

func (*StringSlice) AnyS

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

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.AnyS([]string{"0", "1"}))
Output:

true

func (*StringSlice) AnyW

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

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.AnyW(func(x O) bool {
	return ExB(x.(string) == "2")
}))
Output:

true

func (*StringSlice) Append

func (p *StringSlice) Append(elem interface{}) ISlice

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

Example
slice := NewStringSliceV("1").Append("2").Append("3")
fmt.Println(slice)
Output:

[1 2 3]

func (*StringSlice) AppendV

func (p *StringSlice) AppendV(elems ...interface{}) ISlice

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

Example
slice := NewStringSliceV("1").AppendV("2", "3")
fmt.Println(slice)
Output:

[1 2 3]

func (*StringSlice) At

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

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.At(2))
Output:

3

func (*StringSlice) Clear

func (p *StringSlice) Clear() ISlice

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

Example

Clear --------------------------------------------------------------------------------------------------

slice := NewStringSliceV("1").Concat([]string{"2", "3"})
fmt.Println(slice.Clear())
Output:

[]

func (*StringSlice) Concat

func (p *StringSlice) Concat(slice interface{}) (new ISlice)

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

Example
slice := NewStringSliceV("1").Concat([]string{"2", "3"})
fmt.Println(slice)
Output:

[1 2 3]

func (*StringSlice) ConcatM

func (p *StringSlice) ConcatM(slice interface{}) ISlice

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

Example
slice := NewStringSliceV("1").ConcatM([]string{"2", "3"})
fmt.Println(slice)
Output:

[1 2 3]

func (*StringSlice) Copy

func (p *StringSlice) Copy(indices ...int) (new ISlice)

Copy returns a new Slice with the indicated range of elements copied from this Slice; Expects nothing, in which case everything is copied, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior; Out of bounds indices will be moved within bounds.

An empty Slice is returned if indicies are mutually exclusive or nothing can be returned.

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.Copy())
Output:

[1 2 3]

func (*StringSlice) Count

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

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

Example
slice := NewStringSliceV("1", "2", "2")
fmt.Println(slice.Count("2"))
Output:

2

func (*StringSlice) CountW

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

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

Example
slice := NewStringSliceV("1", "2", "2")
fmt.Println(slice.CountW(func(x O) bool {
	return ExB(x.(string) == "2")
}))
Output:

2

func (*StringSlice) Drop

func (p *StringSlice) Drop(indices ...int) ISlice

Drop modifies this Slice to delete the indicated range of elements and returns a referece to this Slice; Expects nothing, in which case everything is dropped, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that DropAt(0, -1) includes index -1 as opposed to Go's exclusive behavior; Out of bounds indices will be moved within bounds.

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

[3]

func (*StringSlice) DropAt

func (p *StringSlice) DropAt(i int) ISlice

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.DropAt(1))
Output:

[1 3]

func (*StringSlice) DropFirst

func (p *StringSlice) DropFirst() ISlice

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.DropFirst())
Output:

[2 3]

func (*StringSlice) DropFirstN

func (p *StringSlice) DropFirstN(n int) ISlice

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.DropFirstN(2))
Output:

[3]

func (*StringSlice) DropFirstW added in v1.2.4

func (p *StringSlice) DropFirstW(sel func(O) bool) ISlice

DropFirstW modifies this Slice to delete the first elements that match the lambda selector and returns a reference to this Slice; The slice is updated instantly when lambda expression is evaluated not after DropFirstW completes.

func (*StringSlice) DropLast

func (p *StringSlice) DropLast() ISlice

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.DropLast())
Output:

[1 2]

func (*StringSlice) DropLastN

func (p *StringSlice) DropLastN(n int) ISlice

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.DropLastN(2))
Output:

[1]

func (*StringSlice) DropW

func (p *StringSlice) DropW(sel func(O) bool) ISlice

DropW modifies this Slice to delete the elements that match the lambda selector and returns a reference to this Slice; The slice is updated instantly when lambda expression is evaluated not after DropW completes.

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.DropW(func(x O) bool {
	return ExB(Obj(x).ToInt()%2 == 0)
}))
Output:

[1 3]

func (*StringSlice) Each

func (p *StringSlice) Each(action func(O)) ISlice

Each calls the given lambda once for each element in this Slice, passing in that element as a parameter; Returns a reference to this Slice

Example
NewStringSliceV("1", "2", "3").Each(func(x O) {
	fmt.Printf("%v", x)
})
Output:

123

func (*StringSlice) EachE

func (p *StringSlice) EachE(action func(O) error) (ISlice, error)

EachE calls the given lambda once for each element in this Slice, passing in that element as a parameter; Returns a reference to this Slice and any error from the lambda.

Example
NewStringSliceV("1", "2", "3").EachE(func(x O) error {
	fmt.Printf("%v", x)
	return nil
})
Output:

123

func (*StringSlice) EachI

func (p *StringSlice) EachI(action func(int, O)) ISlice

EachI calls the given lambda once for each element in this Slice, passing in the index and element as a parameter; Returns a reference to this Slice

Example
NewStringSliceV("1", "2", "3").EachI(func(i int, x O) {
	fmt.Printf("%v:%v", i, x)
})
Output:

0:11:22:3

func (*StringSlice) EachIE

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

EachIE calls the given lambda once for each element in this Slice, passing in the index and element as a parameter; Returns a reference to this Slice and any error from the lambda.

Example
NewStringSliceV("1", "2", "3").EachIE(func(i int, x O) error {
	fmt.Printf("%v:%v", i, x)
	return nil
})
Output:

0:11:22:3

func (*StringSlice) EachR

func (p *StringSlice) EachR(action func(O)) ISlice

EachR calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter; Returns a reference to this Slice

Example
NewStringSliceV("1", "2", "3").EachR(func(x O) {
	fmt.Printf("%v", x)
})
Output:

321

func (*StringSlice) EachRE

func (p *StringSlice) EachRE(action func(O) error) (ISlice, error)

EachRE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter; Returns a reference to this Slice and any error from the lambda.

Example
NewStringSliceV("1", "2", "3").EachRE(func(x O) error {
	fmt.Printf("%v", x)
	return nil
})
Output:

321

func (*StringSlice) EachRI

func (p *StringSlice) EachRI(action func(int, O)) ISlice

EachRI calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter; Returns a reference to this Slice

Example
NewStringSliceV("1", "2", "3").EachRI(func(i int, x O) {
	fmt.Printf("%v:%v", i, x)
})
Output:

2:31:20:1

func (*StringSlice) EachRIE

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

EachRIE calls the given lambda once for each element in this Slice in reverse, passing in that element as a parameter; Returns a reference to this Slice and any error from the lambda.

Example
NewStringSliceV("1", "2", "3").EachRIE(func(i int, x O) error {
	fmt.Printf("%v:%v", i, x)
	return nil
})
Output:

2:31:20:1

func (*StringSlice) Empty

func (p *StringSlice) Empty() bool

Empty tests if this Slice is empty.

Example

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

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

true

func (*StringSlice) First

func (p *StringSlice) First() (elem *Object)

First returns the first element in this Slice as Object. Object.Nil() == true will be returned when there are no elements in the slice.

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.First())
Output:

1

func (*StringSlice) FirstN

func (p *StringSlice) FirstN(n int) ISlice

FirstN returns the first n elements in this slice as a Slice reference to the original; Best effort is used such that as many as can be will be returned up until the request is satisfied.

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.FirstN(2))
Output:

[1 2]

func (*StringSlice) FirstW added in v1.2.3

func (p *StringSlice) FirstW(sel func(O) bool) (elem *Object)

FirstW returns the first element in this Slice as an Object where the lamda selector returns true Object.Nil() == true will be returned when there are no elements in the slice that match the lambda

func (*StringSlice) G

func (p *StringSlice) G() []string

G returns the underlying data structure as a builtin Go type

Example

G --------------------------------------------------------------------------------------------------

fmt.Println(NewStringSliceV("1", "2", "3").G())
Output:

[1 2 3]

func (*StringSlice) Index

func (p *StringSlice) Index(elem interface{}) (loc int)

Index returns the index of the first element in this Slice where element == elem Returns a -1 if the element was not not found.

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.Index("2"))
Output:

1

func (*StringSlice) Insert

func (p *StringSlice) Insert(i int, obj interface{}) ISlice

Insert modifies this Slice to insert the given elements before the element(s) with the given index; Negative indices count backwards from the end of the slice, where -1 is the last element; If a negative index is used, the given element will be inserted after that element, so using an index of -1 will insert the element at the end of the slice; If a Slice is given all elements will be inserted starting from the beging until the end; Slice is returned for chaining; Invalid index locations will not change the slice.

Example
slice := NewStringSliceV("1", "3")
fmt.Println(slice.Insert(1, "2"))
Output:

[1 2 3]

func (*StringSlice) InterSlice

func (p *StringSlice) InterSlice() bool

InterSlice returns true if the underlying implementation is a RefSlice

func (*StringSlice) Join

func (p *StringSlice) Join(separator ...string) (str *Object)

Join converts each element into a string then joins them together using the given separator or comma by default.

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.Join())
Output:

1,2,3

func (*StringSlice) Last

func (p *StringSlice) Last() (elem *Object)

Last returns the last element in this Slice as an Object; Object.Nil() == true will be returned if there are no elements in the slice.

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.Last())
Output:

3

func (*StringSlice) LastN

func (p *StringSlice) LastN(n int) ISlice

LastN returns the last n elements in this Slice as a Slice reference to the original; Best effort is used such that as many as can be will be returned up until the request is satisfied.

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.LastN(2))
Output:

[2 3]

func (*StringSlice) Len

func (p *StringSlice) Len() int

Len returns the number of elements in this Slice

Example

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

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

3

func (*StringSlice) Less

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

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

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

false

func (*StringSlice) Map

func (p *StringSlice) Map(mod func(O) O) ISlice

Map creates a new slice with the modified elements from the lambda.

Example

Map --------------------------------------------------------------------------------------------------

slice := NewStringSliceV("1", "2", "3")
slice = slice.Map(func(x O) O {
	return ToStr(ToInt(x.(string)) + 1).A()
}).S()
fmt.Println(slice.G())
Output:

[2 3 4]

func (*StringSlice) Nil

func (p *StringSlice) Nil() bool

Nil tests if this Slice is nil

Example

Nil --------------------------------------------------------------------------------------------------

var slice *StringSlice
fmt.Println(slice.Nil())
Output:

true

func (*StringSlice) O

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

O returns the underlying data structure as is

Example

O --------------------------------------------------------------------------------------------------

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

[1 2 3]

func (*StringSlice) Pair

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

Pair simply returns the first and second Slice elements as Objects

Example
slice := NewStringSliceV("1", "2")
first, second := slice.Pair()
fmt.Println(first, second)
Output:

1 2

func (*StringSlice) Pop

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

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.Pop())
Output:

3

func (*StringSlice) PopN

func (p *StringSlice) PopN(n int) (new ISlice)

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.PopN(2))
Output:

[2 3]

func (*StringSlice) Prepend

func (p *StringSlice) Prepend(elem interface{}) ISlice

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

Example
slice := NewStringSliceV("2", "3")
fmt.Println(slice.Prepend("1"))
Output:

[1 2 3]

func (*StringSlice) RefSlice

func (p *StringSlice) RefSlice() bool

RefSlice returns true if the underlying implementation is a RefSlice

func (*StringSlice) Reverse

func (p *StringSlice) Reverse() (new ISlice)

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.Reverse())
Output:

[3 2 1]

func (*StringSlice) ReverseM

func (p *StringSlice) ReverseM() ISlice

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.ReverseM())
Output:

[3 2 1]

func (*StringSlice) S

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

S is an alias to ToStringSlice

func (*StringSlice) Select

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

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.Select(func(x O) bool {
	return ExB(x.(string) == "2" || x.(string) == "3")
}))
Output:

[2 3]

func (*StringSlice) Set

func (p *StringSlice) Set(i int, elem interface{}) ISlice

Set the element(s) at the given index location to the given element(s); Allows for negative notation. Returns a reference to this Slice and swallows any errors.

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

[0 2 3]

func (*StringSlice) SetE

func (p *StringSlice) SetE(i int, elems interface{}) (ISlice, error)

SetE the element(s) at the given index location to the given element(s); Allows for negative notation. Returns a referenc to this Slice and an error if out of bounds or elem is the wrong type.

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

[0 2 3] <nil>

func (*StringSlice) Shift

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

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.Shift())
Output:

1

func (*StringSlice) ShiftN

func (p *StringSlice) ShiftN(n int) (new ISlice)

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.ShiftN(2))
Output:

[1 2]

func (*StringSlice) Single

func (p *StringSlice) Single() bool

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

Example
slice := NewStringSliceV("1")
fmt.Println(slice.Single())
Output:

true

func (*StringSlice) Slice

func (p *StringSlice) Slice(indices ...int) ISlice

Slice returns a range of elements from this Slice as a Slice reference to the original; Allows for negative notation. Expects nothing, in which case everything is included, or two indices i and j, in which case an inclusive behavior is used such that Slice(0, -1) includes index -1 as opposed to Go's exclusive behavior; Out of bounds indices will be moved within bounds;

An empty Slice is returned if indicies are mutually exclusive or nothing can be returned;

e.g. NewStringSliceV(1,2,3).Slice(0, -1) == [1,2,3] && NewStringSliceV(1,2,3).Slice(1,2) == [2,3]

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.Slice(1, -1))
Output:

[2 3]

func (*StringSlice) Sort

func (p *StringSlice) Sort() (new ISlice)

Sort returns a new Slice with sorted elements.

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

[1 2 3]

func (*StringSlice) SortM

func (p *StringSlice) SortM() ISlice

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

Example
slice := NewStringSliceV("2", "3", "1")
fmt.Println(slice.SortM())
Output:

[1 2 3]

func (*StringSlice) SortReverse

func (p *StringSlice) SortReverse() (new ISlice)

SortReverse returns a new Slice sorting the elements in reverse.

Example
slice := NewStringSliceV("2", "3", "1")
fmt.Println(slice.SortReverse())
Output:

[3 2 1]

func (*StringSlice) SortReverseM

func (p *StringSlice) SortReverseM() ISlice

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

Example
slice := NewStringSliceV("2", "3", "1")
fmt.Println(slice.SortReverseM())
Output:

[3 2 1]

func (*StringSlice) String

func (p *StringSlice) String() string

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

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

[1 2 3]

func (*StringSlice) Swap

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

Swap modifies this Slice swapping the indicated elements.

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

[1 2 3]

func (*StringSlice) Take

func (p *StringSlice) Take(indices ...int) (new ISlice)

Take modifies this Slice removing the indicated range of elements from this Slice and returning them as a new Slice; Expects nothing, in which case everything is taken, or two indices i and j, in which case positive and negative notation is supported and uses an inclusive behavior such that Take(0, -1) includes index -1 as opposed to Go's exclusive behavior; Out of bounds indices will be moved within bounds.

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

[1 2]

func (*StringSlice) TakeAt

func (p *StringSlice) TakeAt(i int) (elem *Object)

TakeAt modifies this Slice removing the elemement at the given index location and returns the removed element as an Object; Allows for negative notation.

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.TakeAt(1))
Output:

2

func (*StringSlice) TakeW

func (p *StringSlice) TakeW(sel func(O) bool) (new ISlice)

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

Example
slice := NewStringSliceV("1", "2", "3")
fmt.Println(slice.TakeW(func(x O) bool {
	return ExB(Obj(x).ToInt()%2 == 0)
}))
Output:

[2]

func (*StringSlice) ToIntSlice

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

ToIntSlice converts the underlying slice into a *IntSlice

func (*StringSlice) ToInterSlice

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

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

func (*StringSlice) ToInts

func (p *StringSlice) ToInts() (slice []int)

ToInts converts the underlying slice into a []int

func (*StringSlice) ToStringSlice

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

ToStringSlice converts the underlying slice into a *StringSlice

func (*StringSlice) ToStrs

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

ToStrs converts the underlying slice into a []string slice

func (*StringSlice) Union

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

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

Example
slice := NewStringSliceV("1", "2")
fmt.Println(slice.Union([]string{"2", "3"}))
Output:

[1 2 3]

func (*StringSlice) UnionM

func (p *StringSlice) UnionM(slice interface{}) ISlice

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

Example
slice := NewStringSliceV("1", "2")
fmt.Println(slice.UnionM([]string{"2", "3"}))
Output:

[1 2 3]

func (*StringSlice) Uniq

func (p *StringSlice) Uniq() (new ISlice)

Uniq returns a new Slice with all non uniq elements removed while preserving element order; Cost for this call vs the UniqM is roughly the same, this one is appending that one dropping.

Example
slice := NewStringSliceV("1", "2", "3", "3")
fmt.Println(slice.Uniq())
Output:

[1 2 3]

func (*StringSlice) UniqM

func (p *StringSlice) UniqM() ISlice

UniqM modifies this Slice to remove all non uniq elements while preserving element order; Cost for this call vs the Uniq is roughly the same, this one is dropping that one appending.

Example
slice := NewStringSliceV("1", "2", "3", "3")
fmt.Println(slice.UniqM())
Output:

[1 2 3]

Notes

Bugs

  • The rule Title uses for word boundaries does not handle Unicode punctuation properly. Pass through for strings.Title

Directories

Path Synopsis
pkg
arch
Package arch provides archive and compression helper functions
Package arch provides archive and compression helper functions
arch/tar
Package tar provides helper functions for tar archives
Package tar provides helper functions for tar archives
arch/zip
Package zip provides create and extract implementations
Package zip provides create and extract implementations
buf
Package buf provides various specialized buffers
Package buf provides various specialized buffers
buf/runes
Package runes provides a simpler rune scanner for lexers.
Package runes provides a simpler rune scanner for lexers.
enc
Package enc provides encoding/decoding helper functions
Package enc provides encoding/decoding helper functions
enc/bin
Package bin provides some low level binary protocol helpers
Package bin provides some low level binary protocol helpers
enc/json
Package json provides helper functions for working with json
Package json provides helper functions for working with json
enc/unit
Package unit provides some helpful unit conversions
Package unit provides some helpful unit conversions
enc/yaml
Package yaml provides helper functions for working with yaml
Package yaml provides helper functions for working with yaml
errs
Package errs provides a common set of error for the pkg n
Package errs provides a common set of error for the pkg n
futil
Package futil provides helper functions for interacting with files
Package futil provides helper functions for interacting with files
net
Package net provides simple networking helper functions
Package net provides simple networking helper functions
net/agent
Package agent provides simple agent helper functions
Package agent provides simple agent helper functions
net/mech
Package mech provides some simple automation for working with web sites
Package mech provides some simple automation for working with web sites
opt
Package opt provides common properties for custom types and support for the options pattern.
Package opt provides common properties for custom types and support for the options pattern.
structs
Package structs provides reflection based utilities for working with structs.
Package structs provides reflection based utilities for working with structs.
sys
Package sys provides os level helper functions for interacting with the system
Package sys provides os level helper functions for interacting with the system
term
Package term provides TTY helper functions for prompting for passwords etc...
Package term provides TTY helper functions for prompting for passwords etc...
term/color
Package color provides basic terminal color output via ANSI Escape Codes https://misc.flogisoft.com/bash/tip_colors_and_formatting
Package color provides basic terminal color output via ANSI Escape Codes https://misc.flogisoft.com/bash/tip_colors_and_formatting
time
Package time provides simple time helper functions
Package time provides simple time helper functions
tmpl
Package tmpl does simple template substitutions fast
Package tmpl does simple template substitutions fast

Jump to

Keyboard shortcuts

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