slice

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: MIT Imports: 1 Imported by: 1

README

LICENSE Build Status codecov Go Report Card Godocs

Some great and powerful gopher once said you shouldn't put this kind of stuff in a library because it's so simple. Until you have to write a contains method for the thousandth time.

SLICE

Slice bolts on some generics-ish functionality to native Go data types when represented as a slice. Currently, the following types are supported:

Go Type Slice Type
[]int Int
[]int8 Int8
[]int16 Int16
[]int32 Int32
[]int64 Int64
[]uint UInt
[]uint8 UInt8
[]uint16 UInt16
[]uint32 UInt32
[]uint64 UInt64
[]float32 Float32
[]float64 Float64
[]string String

For the above types, the following operations are supported (x is the type in the slice):

Function Description
IndexOf(x) Get the first index of the searched element in the slice. If the element is not found, this function returns -1
Contains(x) Test to see if slice contains element x
Unique() Returns unique items in slice. The first occurence of an element is the one that is kept
SortAsc() Sort the slice in ascending order
SortDesc() Sort the slice in descending order
Reverse() Reverses the slice
Filter(func(x) bool) Applies a filter function to every item in the slice and return all items where the filter returns true
Map(func(x) x) Iterate over the slice and replace the current value with the computed value
Each(func(x)) Iterate over the slice (non-mutating)
TryEach(func(x) error) (int, error) Iterate over the slice, and halt if an error is returned from user func. Return index of the failed member and the caught error
IfEach(func(x) bool) (int, bool) Iterate over the slice, and halt if false is returned from user func. Return the index of the element that caused the func to return false, and a bool that is true if every member of the slice returned true with the function applied. If all elements return true, the index returned is -1
Chunk(size) Splits the slice into chunks of a specified size
Value() Returns the native type slice value
Performance

Performance benchmarks can be found in benchmarks.txt.

A note about performance, benchmarks, etc

Generics are a way to apply parametric polymorphism to common aggregates.
They are generally very good at hiding complexity, and as a corollary, hide cost as well. With that said, I encourage you to peek at the performance benchmarks I've included in this repo. One thing that should stand out immediately is that cpu time and memory increase proportionally with load.
This should not be surprising at all, but I should point out here that if you expect Filter() or Unique() to be performant with 100,000 elements, then it is likely you may need to pick a more bespoke and optimized approach.

Some examples...
package main

import (
	"fmt"
	
	"github.com/schigh/slice"
)

func main() {
	orig := []string{"foo", "bar", "baz", "fizz", "buzz"}
	startsWithF := slice.String(orig).Filter(func(s string) bool {
		return len(s) > 0 && s[0] == 'f'
	}).Value()
	
	fmt.Println(startsWithF)
	// ["foo", "fizz"]
}
package main

import (
	"fmt"
	
	"github.com/schigh/slice"
)

func main() {
	orig := []int{9,1,6,2,3,4,3,4,5,7,8,9,0}
	unique := slice.Int(orig).Unique().SortDesc().Value()
	
	fmt.Println(unique)
	// [9,8,7,6,5,4,3,2,1,0]
}

Check out the GoDoc for more information.

Generator

The slice generator slicify uses go:generate to add slice functionality to existing structs or interfaces. You may choose which features you'd like to add by setting them in the generate command. For example:

//go:generate slicify User map filter each

Will generate the Map, Filter, and Each functionality (see below) on a User struct's slice type. You could also just say you want everything:

//go:generate slicify User all

This will generate all functions produced by the tool.

Generator Options
Closures

Some generated functions take as their receiver a function that operates on every member of the slice.
By default, these receivers use a function where each member is passed by reference.
For example, the generated Filter function on a User struct:

// Filter evaluates every element in the slice, and returns all User 
// instances where the eval function returns true
func (slc UserSlice) Filter(f func(*User) bool) UserSlice {
	out := make([]User, 0, len(slc))
	for _, v := range slc {
		if f(&v) {
			out = append(out, v)
		}
	}

	return UserSlice(out)
}

The user-defined function receives a pointer to User by default.

If instead you want your slice functions to operate by value, you can modify your generator tags like so:

//go:generate slicify User filter byvalue

This would produce the following function:

// Filter evaluates every element in the slice, and returns all User 
// instances where the eval function returns true
func (slc UserSlice) Filter(f func(User) bool) UserSlice {
	out := make([]User, 0, len(slc))
	for _, v := range slc {
		if f(v) {
			out = append(out, v)
		}
	}

	return UserSlice(out)
}

Note Slice types generated for interfaces are always handled by value.

Pointer Slices

You can also generate pointer slices by prepending an asterisk to your struct name in the go generate directive, like so:

//go:generate slicify *User all

This will generate a type called UserPtrSlice, which is an alias of []*User.
All slice functions take a pointer receiver, for example:

func (slc UserPtrSlice) Map(f func(*User) *User) {
	for i, v := range slc {
		slice[i] = f(v)
	}
}

Documentation

Index

Examples

Constants

View Source
const (
	// NotInSlice signifies that the searched element is not in a slice
	NotInSlice = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Float32

type Float32 []float32

Float32 is the alias of []float32

func (Float32) Chunk

func (slc Float32) Chunk(size int) [][]float32

Chunk will divide the slice of float32 into smaller slicify defined by chunk length

func (Float32) Contains

func (slc Float32) Contains(needle float32) bool

Contains returns true if the slice contains needle

func (Float32) Each

func (slc Float32) Each(f func(float32))

Each will apply a function to each float32 in the slice. This function will iterate over the slice completely. No items in the slice should be mutated by this operation.

func (Float32) Filter

func (slc Float32) Filter(f func(float32) bool) Float32

Filter will return all float32 values that evaluate true in the user-supplied function

func (Float32) IfEach

func (slc Float32) IfEach(f func(float32) bool) (int, bool)

IfEach will apply a function to each float32 in the slice. If the function returns false, the iteration will stop and return the index of the element that caused the function to return false. The second returned value will be true if all members of the slice cause the provided function to return true, and false otherwise. No items in the slice should be mutated by this operation.

func (Float32) IndexOf

func (slc Float32) IndexOf(needle float32) int

IndexOf returns the first index of needle, or -1 if not found

func (Float32) Map

func (slc Float32) Map(f func(float32) float32)

Map will apply a function to each float32 in the slice and replace the previous value

func (Float32) Reverse

func (slc Float32) Reverse() Float32

Reverse will reverse the order of the slice

func (Float32) SortAsc

func (slc Float32) SortAsc() Float32

SortAsc will sort the slice in ascending order

func (Float32) SortDesc

func (slc Float32) SortDesc() Float32

SortDesc will sort the slice in descending order

func (Float32) TryEach

func (slc Float32) TryEach(f func(float32) error) (int, error)

TryEach will apply a function to each float32 in the slice. If the function returns an error, the iteration will stop and return the index of the element that caused the function to return the error. The second returned value will be first error returned from the supplied function, and nil otherwise. No items in the slice should be mutated by this operation.

func (Float32) Unique

func (slc Float32) Unique() Float32

Unique filters out duplicate float32 values

func (Float32) Value

func (slc Float32) Value() []float32

Value returns the aliased []float32

type Float64

type Float64 []float64

Float64 is the alias of []float64

func (Float64) Chunk

func (slc Float64) Chunk(size int) [][]float64

Chunk will divide the slice of float64 into smaller slicify defined by chunk length

func (Float64) Contains

func (slc Float64) Contains(needle float64) bool

Contains returns true if the slice contains needle

func (Float64) Each

func (slc Float64) Each(f func(float64))

Each will apply a function to each float64 in the slice. This function will iterate over the slice completely. No items in the slice should be mutated by this operation.

func (Float64) Filter

func (slc Float64) Filter(f func(float64) bool) Float64

Filter will return all float64 values that evaluate true in the user-supplied function

func (Float64) IfEach

func (slc Float64) IfEach(f func(float64) bool) (int, bool)

IfEach will apply a function to each float64 in the slice. If the function returns false, the iteration will stop and return the index of the element that caused the function to return false. The second returned value will be true if all members of the slice cause the provided function to return true, and false otherwise. No items in the slice should be mutated by this operation.

func (Float64) IndexOf

func (slc Float64) IndexOf(needle float64) int

IndexOf returns the first index of needle, or -1 if not found

func (Float64) Map

func (slc Float64) Map(f func(float64) float64)

Map will apply a function to each float64 in the slice and replace the previous value

func (Float64) Reverse

func (slc Float64) Reverse() Float64

Reverse will reverse the order of the slice

func (Float64) SortAsc

func (slc Float64) SortAsc() Float64

SortAsc will sort the slice in ascending order

func (Float64) SortDesc

func (slc Float64) SortDesc() Float64

SortDesc will sort the slice in descending order

func (Float64) TryEach

func (slc Float64) TryEach(f func(float64) error) (int, error)

TryEach will apply a function to each float64 in the slice. If the function returns an error, the iteration will stop and return the index of the element that caused the function to return the error. The second returned value will be first error returned from the supplied function, and nil otherwise. No items in the slice should be mutated by this operation.

func (Float64) Unique

func (slc Float64) Unique() Float64

Unique filters out duplicate float64 values

func (Float64) Value

func (slc Float64) Value() []float64

Value returns the aliased []float64

type Int

type Int []int

Int is the alias of []int

func (Int) Chunk

func (slc Int) Chunk(size int) [][]int

Chunk will divide the slice of int into smaller slicify defined by chunk length

func (Int) Contains

func (slc Int) Contains(needle int) bool

Contains returns true if the slice contains needle

func (Int) Each

func (slc Int) Each(f func(int))

Each will apply a function to each int in the slice. This function will iterate over the slice completely. No items in the slice should be mutated by this operation.

func (Int) Filter

func (slc Int) Filter(f func(int) bool) Int

Filter will return all int values that evaluate true in the user-supplied function

func (Int) IfEach

func (slc Int) IfEach(f func(int) bool) (int, bool)

IfEach will apply a function to each int in the slice. If the function returns false, the iteration will stop and return the index of the element that caused the function to return false. The second returned value will be true if all members of the slice cause the provided function to return true, and false otherwise. No items in the slice should be mutated by this operation.

func (Int) IndexOf

func (slc Int) IndexOf(needle int) int

IndexOf returns the first index of needle, or -1 if not found

func (Int) Map

func (slc Int) Map(f func(int) int)

Map will apply a function to each int in the slice and replace the previous value

func (Int) Reverse

func (slc Int) Reverse() Int

Reverse will reverse the order of the slice

func (Int) SortAsc

func (slc Int) SortAsc() Int

SortAsc will sort the slice in ascending order

func (Int) SortDesc

func (slc Int) SortDesc() Int

SortDesc will sort the slice in descending order

func (Int) TryEach

func (slc Int) TryEach(f func(int) error) (int, error)

TryEach will apply a function to each int in the slice. If the function returns an error, the iteration will stop and return the index of the element that caused the function to return the error. The second returned value will be first error returned from the supplied function, and nil otherwise. No items in the slice should be mutated by this operation.

func (Int) Unique

func (slc Int) Unique() Int

Unique filters out duplicate int values

func (Int) Value

func (slc Int) Value() []int

Value returns the aliased []int

type Int16

type Int16 []int16

Int16 is the alias of []int16

func (Int16) Chunk

func (slc Int16) Chunk(size int) [][]int16

Chunk will divide the slice of int16 into smaller slicify defined by chunk length

func (Int16) Contains

func (slc Int16) Contains(needle int16) bool

Contains returns true if the slice contains needle

func (Int16) Each

func (slc Int16) Each(f func(int16))

Each will apply a function to each int16 in the slice. This function will iterate over the slice completely. No items in the slice should be mutated by this operation.

func (Int16) Filter

func (slc Int16) Filter(f func(int16) bool) Int16

Filter will return all int16 values that evaluate true in the user-supplied function

func (Int16) IfEach

func (slc Int16) IfEach(f func(int16) bool) (int, bool)

IfEach will apply a function to each int16 in the slice. If the function returns false, the iteration will stop and return the index of the element that caused the function to return false. The second returned value will be true if all members of the slice cause the provided function to return true, and false otherwise. No items in the slice should be mutated by this operation.

func (Int16) IndexOf

func (slc Int16) IndexOf(needle int16) int

IndexOf returns the first index of needle, or -1 if not found

func (Int16) Map

func (slc Int16) Map(f func(int16) int16)

Map will apply a function to each int16 in the slice and replace the previous value

func (Int16) Reverse

func (slc Int16) Reverse() Int16

Reverse will reverse the order of the slice

func (Int16) SortAsc

func (slc Int16) SortAsc() Int16

SortAsc will sort the slice in ascending order

func (Int16) SortDesc

func (slc Int16) SortDesc() Int16

SortDesc will sort the slice in descending order

func (Int16) TryEach

func (slc Int16) TryEach(f func(int16) error) (int, error)

TryEach will apply a function to each int16 in the slice. If the function returns an error, the iteration will stop and return the index of the element that caused the function to return the error. The second returned value will be first error returned from the supplied function, and nil otherwise. No items in the slice should be mutated by this operation.

func (Int16) Unique

func (slc Int16) Unique() Int16

Unique filters out duplicate int16 values

func (Int16) Value

func (slc Int16) Value() []int16

Value returns the aliased []int16

type Int32

type Int32 []int32

Int32 is the alias of []int32

func (Int32) Chunk

func (slc Int32) Chunk(size int) [][]int32

Chunk will divide the slice of int32 into smaller slicify defined by chunk length

func (Int32) Contains

func (slc Int32) Contains(needle int32) bool

Contains returns true if the slice contains needle

func (Int32) Each

func (slc Int32) Each(f func(int32))

Each will apply a function to each int32 in the slice. This function will iterate over the slice completely. No items in the slice should be mutated by this operation.

func (Int32) Filter

func (slc Int32) Filter(f func(int32) bool) Int32

Filter will return all int32 values that evaluate true in the user-supplied function

func (Int32) IfEach

func (slc Int32) IfEach(f func(int32) bool) (int, bool)

IfEach will apply a function to each int32 in the slice. If the function returns false, the iteration will stop and return the index of the element that caused the function to return false. The second returned value will be true if all members of the slice cause the provided function to return true, and false otherwise. No items in the slice should be mutated by this operation.

func (Int32) IndexOf

func (slc Int32) IndexOf(needle int32) int

IndexOf returns the first index of needle, or -1 if not found

func (Int32) Map

func (slc Int32) Map(f func(int32) int32)

Map will apply a function to each int32 in the slice and replace the previous value

func (Int32) Reverse

func (slc Int32) Reverse() Int32

Reverse will reverse the order of the slice

func (Int32) SortAsc

func (slc Int32) SortAsc() Int32

SortAsc will sort the slice in ascending order

func (Int32) SortDesc

func (slc Int32) SortDesc() Int32

SortDesc will sort the slice in descending order

func (Int32) TryEach

func (slc Int32) TryEach(f func(int32) error) (int, error)

TryEach will apply a function to each int32 in the slice. If the function returns an error, the iteration will stop and return the index of the element that caused the function to return the error. The second returned value will be first error returned from the supplied function, and nil otherwise. No items in the slice should be mutated by this operation.

func (Int32) Unique

func (slc Int32) Unique() Int32

Unique filters out duplicate int32 values

func (Int32) Value

func (slc Int32) Value() []int32

Value returns the aliased []int32

type Int64

type Int64 []int64

Int64 is the alias of []int64

func (Int64) Chunk

func (slc Int64) Chunk(size int) [][]int64

Chunk will divide the slice of int64 into smaller slicify defined by chunk length

func (Int64) Contains

func (slc Int64) Contains(needle int64) bool

Contains returns true if the slice contains needle

func (Int64) Each

func (slc Int64) Each(f func(int64))

Each will apply a function to each int64 in the slice. This function will iterate over the slice completely. No items in the slice should be mutated by this operation.

func (Int64) Filter

func (slc Int64) Filter(f func(int64) bool) Int64

Filter will return all int64 values that evaluate true in the user-supplied function

func (Int64) IfEach

func (slc Int64) IfEach(f func(int64) bool) (int, bool)

IfEach will apply a function to each int64 in the slice. If the function returns false, the iteration will stop and return the index of the element that caused the function to return false. The second returned value will be true if all members of the slice cause the provided function to return true, and false otherwise. No items in the slice should be mutated by this operation.

func (Int64) IndexOf

func (slc Int64) IndexOf(needle int64) int

IndexOf returns the first index of needle, or -1 if not found

func (Int64) Map

func (slc Int64) Map(f func(int64) int64)

Map will apply a function to each int64 in the slice and replace the previous value

func (Int64) Reverse

func (slc Int64) Reverse() Int64

Reverse will reverse the order of the slice

func (Int64) SortAsc

func (slc Int64) SortAsc() Int64

SortAsc will sort the slice in ascending order

func (Int64) SortDesc

func (slc Int64) SortDesc() Int64

SortDesc will sort the slice in descending order

func (Int64) TryEach

func (slc Int64) TryEach(f func(int64) error) (int, error)

TryEach will apply a function to each int64 in the slice. If the function returns an error, the iteration will stop and return the index of the element that caused the function to return the error. The second returned value will be first error returned from the supplied function, and nil otherwise. No items in the slice should be mutated by this operation.

func (Int64) Unique

func (slc Int64) Unique() Int64

Unique filters out duplicate int64 values

func (Int64) Value

func (slc Int64) Value() []int64

Value returns the aliased []int64

type Int8

type Int8 []int8

Int8 is the alias of []int8

func (Int8) Chunk

func (slc Int8) Chunk(size int) [][]int8

Chunk will divide the slice of int8 into smaller slicify defined by chunk length

func (Int8) Contains

func (slc Int8) Contains(needle int8) bool

Contains returns true if the slice contains needle

func (Int8) Each

func (slc Int8) Each(f func(int8))

Each will apply a function to each int8 in the slice. This function will iterate over the slice completely. No items in the slice should be mutated by this operation.

func (Int8) Filter

func (slc Int8) Filter(f func(int8) bool) Int8

Filter will return all int8 values that evaluate true in the user-supplied function

func (Int8) IfEach

func (slc Int8) IfEach(f func(int8) bool) (int, bool)

IfEach will apply a function to each int8 in the slice. If the function returns false, the iteration will stop and return the index of the element that caused the function to return false. The second returned value will be true if all members of the slice cause the provided function to return true, and false otherwise. No items in the slice should be mutated by this operation.

func (Int8) IndexOf

func (slc Int8) IndexOf(needle int8) int

IndexOf returns the first index of needle, or -1 if not found

func (Int8) Map

func (slc Int8) Map(f func(int8) int8)

Map will apply a function to each int8 in the slice and replace the previous value

func (Int8) Reverse

func (slc Int8) Reverse() Int8

Reverse will reverse the order of the slice

func (Int8) SortAsc

func (slc Int8) SortAsc() Int8

SortAsc will sort the slice in ascending order

func (Int8) SortDesc

func (slc Int8) SortDesc() Int8

SortDesc will sort the slice in descending order

func (Int8) TryEach

func (slc Int8) TryEach(f func(int8) error) (int, error)

TryEach will apply a function to each int8 in the slice. If the function returns an error, the iteration will stop and return the index of the element that caused the function to return the error. The second returned value will be first error returned from the supplied function, and nil otherwise. No items in the slice should be mutated by this operation.

func (Int8) Unique

func (slc Int8) Unique() Int8

Unique filters out duplicate int8 values

func (Int8) Value

func (slc Int8) Value() []int8

Value returns the aliased []int8

type String

type String []string

String is the alias of []string

func (String) Chunk

func (slc String) Chunk(size int) [][]string

Chunk will divide the slice of string into smaller slicify defined by chunk length

Example
package main

import (
	"fmt"

	"github.com/schigh/slice"
)

func main() {
	slc := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"}

	chunks := slice.String(slc).Chunk(4)

	for _, chunk := range chunks {
		fmt.Printf("%v\n", chunk)
	}

}
Output:

[a b c d]
[e f g h]
[i j k l]
[m]

func (String) Contains

func (slc String) Contains(needle string) bool

Contains returns true if the slice contains needle

func (String) Each

func (slc String) Each(f func(string))

Each will apply a function to each string in the slice. This function will iterate over the slice completely. No items in the slice should be mutated by this operation.

Example
package main

import (
	"fmt"
	"sync/atomic"

	"github.com/schigh/slice"
)

func main() {
	var v atomic.Value
	v.Store("")

	slc := []string{"h", "e", "l", "l", "o", ",", " ", "w", "o", "r", "l", "d", "!"}
	slice.String(slc).Each(func(s string) {
		vv := v.Load().(string)
		vv = vv + s
		v.Store(vv)
	})

	vv := v.Load().(string)
	fmt.Println(vv)

}
Output:

hello, world!

func (String) Filter

func (slc String) Filter(f func(string) bool) String

Filter will return all string values that evaluate true in the user-supplied function

Example
package main

import (
	"fmt"

	"github.com/schigh/slice"
)

func main() {
	slc := []string{"foo", "bar", "baz", "fizz", "buzz"}

	// starts with f
	fslice := slice.String(slc).Filter(func(s string) bool {
		return s != "" && s[0] == 'f'
	})

	// starts with b
	bslice := slice.String(slc).Filter(func(s string) bool {
		return s != "" && s[0] == 'b'
	})

	fmt.Printf("%v\n", fslice)
	fmt.Printf("%v\n", bslice)

}
Output:

[foo fizz]
[bar baz buzz]

func (String) IfEach

func (slc String) IfEach(f func(string) bool) (int, bool)

IfEach will apply a function to each string in the slice. If the function returns false, the iteration will stop and return the index of the element that caused the function to return false. The second returned value will be true if all members of the slice cause the provided function to return true, and false otherwise. No items in the slice should be mutated by this operation.

func (String) IndexOf

func (slc String) IndexOf(needle string) int

IndexOf returns the first index of needle, or -1 if not found

func (String) Map

func (slc String) Map(f func(string) string)

Map will apply a function to each string in the slice and replace the previous value

Example
package main

import (
	"fmt"
	"strings"

	"github.com/schigh/slice"
)

func main() {
	slc := []string{"foo", "bar", "baz", "fizz", "buzz"}

	slice.String(slc).Map(func(s string) string {
		return strings.ToUpper(s)
	})

	fmt.Printf("%v\n", slc)

}
Output:

[FOO BAR BAZ FIZZ BUZZ]

func (String) Reverse

func (slc String) Reverse() String

Reverse will reverse the order of the slice

func (String) SortAsc

func (slc String) SortAsc() String

SortAsc will sort the slice in ascending order

func (String) SortDesc

func (slc String) SortDesc() String

SortDesc will sort the slice in descending order

func (String) TryEach

func (slc String) TryEach(f func(string) error) (int, error)

TryEach will apply a function to each string in the slice. If the function returns an error, the iteration will stop and return the index of the element that caused the function to return the error. The second returned value will be first error returned from the supplied function, and nil otherwise. No items in the slice should be mutated by this operation.

func (String) Unique

func (slc String) Unique() String

Unique filters out duplicate string values

func (String) Value

func (slc String) Value() []string

Value returns the aliased []string

type UInt

type UInt []uint

UInt is the alias of []uint

func (UInt) Chunk

func (slc UInt) Chunk(size int) [][]uint

Chunk will divide the slice of uint into smaller slicify defined by chunk length

func (UInt) Contains

func (slc UInt) Contains(needle uint) bool

Contains returns true if the slice contains needle

func (UInt) Each

func (slc UInt) Each(f func(uint))

Each will apply a function to each uint in the slice. This function will iterate over the slice completely. No items in the slice should be mutated by this operation.

func (UInt) Filter

func (slc UInt) Filter(f func(uint) bool) UInt

Filter will return all uint values that evaluate true in the user-supplied function

func (UInt) IfEach

func (slc UInt) IfEach(f func(uint) bool) (int, bool)

IfEach will apply a function to each uint in the slice. If the function returns false, the iteration will stop and return the index of the element that caused the function to return false. The second returned value will be true if all members of the slice cause the provided function to return true, and false otherwise. No items in the slice should be mutated by this operation.

func (UInt) IndexOf

func (slc UInt) IndexOf(needle uint) int

IndexOf returns the first index of needle, or -1 if not found

func (UInt) Map

func (slc UInt) Map(f func(uint) uint)

Map will apply a function to each uint in the slice and replace the previous value

func (UInt) Reverse

func (slc UInt) Reverse() UInt

Reverse will reverse the order of the slice

func (UInt) SortAsc

func (slc UInt) SortAsc() UInt

SortAsc will sort the slice in ascending order

func (UInt) SortDesc

func (slc UInt) SortDesc() UInt

SortDesc will sort the slice in descending order

func (UInt) TryEach

func (slc UInt) TryEach(f func(uint) error) (int, error)

TryEach will apply a function to each uint in the slice. If the function returns an error, the iteration will stop and return the index of the element that caused the function to return the error. The second returned value will be first error returned from the supplied function, and nil otherwise. No items in the slice should be mutated by this operation.

func (UInt) Unique

func (slc UInt) Unique() UInt

Unique filters out duplicate uint values

func (UInt) Value

func (slc UInt) Value() []uint

Value returns the aliased []uint

type UInt16

type UInt16 []uint16

UInt16 is the alias of []uint16

func (UInt16) Chunk

func (slc UInt16) Chunk(size int) [][]uint16

Chunk will divide the slice of uint16 into smaller slicify defined by chunk length

func (UInt16) Contains

func (slc UInt16) Contains(needle uint16) bool

Contains returns true if the slice contains needle

func (UInt16) Each

func (slc UInt16) Each(f func(uint16))

Each will apply a function to each uint16 in the slice. This function will iterate over the slice completely. No items in the slice should be mutated by this operation.

func (UInt16) Filter

func (slc UInt16) Filter(f func(uint16) bool) UInt16

Filter will return all uint16 values that evaluate true in the user-supplied function

func (UInt16) IfEach

func (slc UInt16) IfEach(f func(uint16) bool) (int, bool)

IfEach will apply a function to each uint16 in the slice. If the function returns false, the iteration will stop and return the index of the element that caused the function to return false. The second returned value will be true if all members of the slice cause the provided function to return true, and false otherwise. No items in the slice should be mutated by this operation.

func (UInt16) IndexOf

func (slc UInt16) IndexOf(needle uint16) int

IndexOf returns the first index of needle, or -1 if not found

func (UInt16) Map

func (slc UInt16) Map(f func(uint16) uint16)

Map will apply a function to each uint16 in the slice and replace the previous value

func (UInt16) Reverse

func (slc UInt16) Reverse() UInt16

Reverse will reverse the order of the slice

func (UInt16) SortAsc

func (slc UInt16) SortAsc() UInt16

SortAsc will sort the slice in ascending order

func (UInt16) SortDesc

func (slc UInt16) SortDesc() UInt16

SortDesc will sort the slice in descending order

func (UInt16) TryEach

func (slc UInt16) TryEach(f func(uint16) error) (int, error)

TryEach will apply a function to each uint16 in the slice. If the function returns an error, the iteration will stop and return the index of the element that caused the function to return the error. The second returned value will be first error returned from the supplied function, and nil otherwise. No items in the slice should be mutated by this operation.

func (UInt16) Unique

func (slc UInt16) Unique() UInt16

Unique filters out duplicate uint16 values

func (UInt16) Value

func (slc UInt16) Value() []uint16

Value returns the aliased []uint16

type UInt32

type UInt32 []uint32

UInt32 is the alias of []uint32

func (UInt32) Chunk

func (slc UInt32) Chunk(size int) [][]uint32

Chunk will divide the slice of uint32 into smaller slicify defined by chunk length

func (UInt32) Contains

func (slc UInt32) Contains(needle uint32) bool

Contains returns true if the slice contains needle

func (UInt32) Each

func (slc UInt32) Each(f func(uint32))

Each will apply a function to each uint32 in the slice. This function will iterate over the slice completely. No items in the slice should be mutated by this operation.

func (UInt32) Filter

func (slc UInt32) Filter(f func(uint32) bool) UInt32

Filter will return all uint32 values that evaluate true in the user-supplied function

func (UInt32) IfEach

func (slc UInt32) IfEach(f func(uint32) bool) (int, bool)

IfEach will apply a function to each uint32 in the slice. If the function returns false, the iteration will stop and return the index of the element that caused the function to return false. The second returned value will be true if all members of the slice cause the provided function to return true, and false otherwise. No items in the slice should be mutated by this operation.

func (UInt32) IndexOf

func (slc UInt32) IndexOf(needle uint32) int

IndexOf returns the first index of needle, or -1 if not found

func (UInt32) Map

func (slc UInt32) Map(f func(uint32) uint32)

Map will apply a function to each uint32 in the slice and replace the previous value

func (UInt32) Reverse

func (slc UInt32) Reverse() UInt32

Reverse will reverse the order of the slice

func (UInt32) SortAsc

func (slc UInt32) SortAsc() UInt32

SortAsc will sort the slice in ascending order

func (UInt32) SortDesc

func (slc UInt32) SortDesc() UInt32

SortDesc will sort the slice in descending order

func (UInt32) TryEach

func (slc UInt32) TryEach(f func(uint32) error) (int, error)

TryEach will apply a function to each uint32 in the slice. If the function returns an error, the iteration will stop and return the index of the element that caused the function to return the error. The second returned value will be first error returned from the supplied function, and nil otherwise. No items in the slice should be mutated by this operation.

func (UInt32) Unique

func (slc UInt32) Unique() UInt32

Unique filters out duplicate uint32 values

func (UInt32) Value

func (slc UInt32) Value() []uint32

Value returns the aliased []uint32

type UInt64

type UInt64 []uint64

UInt64 is the alias of []uint64

func (UInt64) Chunk

func (slc UInt64) Chunk(size int) [][]uint64

Chunk will divide the slice of uint64 into smaller slicify defined by chunk length

func (UInt64) Contains

func (slc UInt64) Contains(needle uint64) bool

Contains returns true if the slice contains needle

func (UInt64) Each

func (slc UInt64) Each(f func(uint64))

Each will apply a function to each uint64 in the slice. This function will iterate over the slice completely. No items in the slice should be mutated by this operation.

func (UInt64) Filter

func (slc UInt64) Filter(f func(uint64) bool) UInt64

Filter will return all uint64 values that evaluate true in the user-supplied function

func (UInt64) IfEach

func (slc UInt64) IfEach(f func(uint64) bool) (int, bool)

IfEach will apply a function to each uint64 in the slice. If the function returns false, the iteration will stop and return the index of the element that caused the function to return false. The second returned value will be true if all members of the slice cause the provided function to return true, and false otherwise. No items in the slice should be mutated by this operation.

func (UInt64) IndexOf

func (slc UInt64) IndexOf(needle uint64) int

IndexOf returns the first index of needle, or -1 if not found

func (UInt64) Map

func (slc UInt64) Map(f func(uint64) uint64)

Map will apply a function to each uint64 in the slice and replace the previous value

func (UInt64) Reverse

func (slc UInt64) Reverse() UInt64

Reverse will reverse the order of the slice

func (UInt64) SortAsc

func (slc UInt64) SortAsc() UInt64

SortAsc will sort the slice in ascending order

func (UInt64) SortDesc

func (slc UInt64) SortDesc() UInt64

SortDesc will sort the slice in descending order

func (UInt64) TryEach

func (slc UInt64) TryEach(f func(uint64) error) (int, error)

TryEach will apply a function to each uint64 in the slice. If the function returns an error, the iteration will stop and return the index of the element that caused the function to return the error. The second returned value will be first error returned from the supplied function, and nil otherwise. No items in the slice should be mutated by this operation.

func (UInt64) Unique

func (slc UInt64) Unique() UInt64

Unique filters out duplicate uint64 values

func (UInt64) Value

func (slc UInt64) Value() []uint64

Value returns the aliased []uint64

type UInt8

type UInt8 []uint8

UInt8 is the alias of []uint8

func (UInt8) Chunk

func (slc UInt8) Chunk(size int) [][]uint8

Chunk will divide the slice of uint8 into smaller slicify defined by chunk length

func (UInt8) Contains

func (slc UInt8) Contains(needle uint8) bool

Contains returns true if the slice contains needle

func (UInt8) Each

func (slc UInt8) Each(f func(uint8))

Each will apply a function to each uint8 in the slice. This function will iterate over the slice completely. No items in the slice should be mutated by this operation.

func (UInt8) Filter

func (slc UInt8) Filter(f func(uint8) bool) UInt8

Filter will return all uint8 values that evaluate true in the user-supplied function

func (UInt8) IfEach

func (slc UInt8) IfEach(f func(uint8) bool) (int, bool)

IfEach will apply a function to each uint8 in the slice. If the function returns false, the iteration will stop and return the index of the element that caused the function to return false. The second returned value will be true if all members of the slice cause the provided function to return true, and false otherwise. No items in the slice should be mutated by this operation.

func (UInt8) IndexOf

func (slc UInt8) IndexOf(needle uint8) int

IndexOf returns the first index of needle, or -1 if not found

func (UInt8) Map

func (slc UInt8) Map(f func(uint8) uint8)

Map will apply a function to each uint8 in the slice and replace the previous value

func (UInt8) Reverse

func (slc UInt8) Reverse() UInt8

Reverse will reverse the order of the slice

func (UInt8) SortAsc

func (slc UInt8) SortAsc() UInt8

SortAsc will sort the slice in ascending order

func (UInt8) SortDesc

func (slc UInt8) SortDesc() UInt8

SortDesc will sort the slice in descending order

func (UInt8) TryEach

func (slc UInt8) TryEach(f func(uint8) error) (int, error)

TryEach will apply a function to each uint8 in the slice. If the function returns an error, the iteration will stop and return the index of the element that caused the function to return the error. The second returned value will be first error returned from the supplied function, and nil otherwise. No items in the slice should be mutated by this operation.

func (UInt8) Unique

func (slc UInt8) Unique() UInt8

Unique filters out duplicate uint8 values

func (UInt8) Value

func (slc UInt8) Value() []uint8

Value returns the aliased []uint8

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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