slices

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2019 License: MIT Imports: 1 Imported by: 0

README

LICENSE Build Status codecov Go Report Card Godocs

slices

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

Go Slice Type Slices Type xtra
[]int IntSlice benchmark
[]int8 Int8Slice benchmark
[]int16 Int16Slice benchmark
[]int32 Int32Slice benchmark
[]int64 Int64Slice benchmark
[]uint UIntSlice benchmark
[]uint8 UInt8Slice benchmark
[]uint16 UInt16Slice benchmark
[]uint32 UInt32Slice benchmark
[]uint64 UInt64Slice benchmark
[]uintptr UIntPtrSlice benchmark
[]float32 Float32Slice benchmark
[]float64 Float64Slice benchmark
[]string StringSlice benchmark

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

Some examples...

package main

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

func main() {
	orig := []string{"foo", "bar", "baz", "fizz", "buzz"}
	startsWithF := slices.StringSlice(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/slices"
)

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

Check out the GoDoc for more information.

Slice Generator

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

//go:generate slices 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 slices 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 (slice UserSlice) Filter(f func(*User) bool) UserSlice {
	out := make([]User, 0, len(slice))
	for _, v := range slice {
		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 slices 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 (slice UserSlice) Filter(f func(User) bool) UserSlice {
	out := make([]User, 0, len(slice))
	for _, v := range slice {
		if f(v) {
			out = append(out, v)
		}
	}

	return UserSlice(out)
}

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 slices *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 (slice UserPtrSlice) Map(f func(*User) *User) {
	for i, v := range slice {
		slice[i] = f(v)
	}
}

Documentation

Index

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 Float32Slice

type Float32Slice []float32

Float32Slice is the alias of []float32

func (Float32Slice) Chunk added in v0.0.5

func (slice Float32Slice) Chunk(size int) [][]float32

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

func (Float32Slice) Contains

func (slice Float32Slice) Contains(needle float32) bool

Contains returns true if the slice contains needle

func (Float32Slice) Each

func (slice Float32Slice) 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 (Float32Slice) Filter

func (slice Float32Slice) Filter(f func(float32) bool) Float32Slice

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

func (Float32Slice) IfEach added in v0.0.4

func (slice Float32Slice) 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 (Float32Slice) IndexOf

func (slice Float32Slice) IndexOf(needle float32) int

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

func (Float32Slice) Map

func (slice Float32Slice) Map(f func(float32) float32)

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

func (Float32Slice) Reverse

func (slice Float32Slice) Reverse() Float32Slice

Reverse will reverse the order of the slice

func (Float32Slice) SortAsc

func (slice Float32Slice) SortAsc() Float32Slice

SortAsc will sort the slice in ascending order

func (Float32Slice) SortDesc

func (slice Float32Slice) SortDesc() Float32Slice

SortDesc will sort the slice in descending order

func (Float32Slice) TryEach added in v0.0.4

func (slice Float32Slice) 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 (Float32Slice) Unique

func (slice Float32Slice) Unique() Float32Slice

Unique filters out duplicate float32 values

func (Float32Slice) Value

func (slice Float32Slice) Value() []float32

Value returns the aliased []float32

type Float64Slice

type Float64Slice []float64

Float64Slice is the alias of []float64

func (Float64Slice) Chunk added in v0.0.5

func (slice Float64Slice) Chunk(size int) [][]float64

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

func (Float64Slice) Contains

func (slice Float64Slice) Contains(needle float64) bool

Contains returns true if the slice contains needle

func (Float64Slice) Each

func (slice Float64Slice) 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 (Float64Slice) Filter

func (slice Float64Slice) Filter(f func(float64) bool) Float64Slice

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

func (Float64Slice) IfEach added in v0.0.4

func (slice Float64Slice) 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 (Float64Slice) IndexOf

func (slice Float64Slice) IndexOf(needle float64) int

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

func (Float64Slice) Map

func (slice Float64Slice) Map(f func(float64) float64)

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

func (Float64Slice) Reverse

func (slice Float64Slice) Reverse() Float64Slice

Reverse will reverse the order of the slice

func (Float64Slice) SortAsc

func (slice Float64Slice) SortAsc() Float64Slice

SortAsc will sort the slice in ascending order

func (Float64Slice) SortDesc

func (slice Float64Slice) SortDesc() Float64Slice

SortDesc will sort the slice in descending order

func (Float64Slice) TryEach added in v0.0.4

func (slice Float64Slice) 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 (Float64Slice) Unique

func (slice Float64Slice) Unique() Float64Slice

Unique filters out duplicate float64 values

func (Float64Slice) Value

func (slice Float64Slice) Value() []float64

Value returns the aliased []float64

type Int16Slice

type Int16Slice []int16

Int16Slice is the alias of []int16

func (Int16Slice) Chunk added in v0.0.5

func (slice Int16Slice) Chunk(size int) [][]int16

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

func (Int16Slice) Contains

func (slice Int16Slice) Contains(needle int16) bool

Contains returns true if the slice contains needle

func (Int16Slice) Each

func (slice Int16Slice) 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 (Int16Slice) Filter

func (slice Int16Slice) Filter(f func(int16) bool) Int16Slice

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

func (Int16Slice) IfEach added in v0.0.4

func (slice Int16Slice) 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 (Int16Slice) IndexOf

func (slice Int16Slice) IndexOf(needle int16) int

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

func (Int16Slice) Map

func (slice Int16Slice) Map(f func(int16) int16)

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

func (Int16Slice) Reverse

func (slice Int16Slice) Reverse() Int16Slice

Reverse will reverse the order of the slice

func (Int16Slice) SortAsc

func (slice Int16Slice) SortAsc() Int16Slice

SortAsc will sort the slice in ascending order

func (Int16Slice) SortDesc

func (slice Int16Slice) SortDesc() Int16Slice

SortDesc will sort the slice in descending order

func (Int16Slice) TryEach added in v0.0.4

func (slice Int16Slice) 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 (Int16Slice) Unique

func (slice Int16Slice) Unique() Int16Slice

Unique filters out duplicate int16 values

func (Int16Slice) Value

func (slice Int16Slice) Value() []int16

Value returns the aliased []int16

type Int32Slice

type Int32Slice []int32

Int32Slice is the alias of []int32

func (Int32Slice) Chunk added in v0.0.5

func (slice Int32Slice) Chunk(size int) [][]int32

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

func (Int32Slice) Contains

func (slice Int32Slice) Contains(needle int32) bool

Contains returns true if the slice contains needle

func (Int32Slice) Each

func (slice Int32Slice) 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 (Int32Slice) Filter

func (slice Int32Slice) Filter(f func(int32) bool) Int32Slice

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

func (Int32Slice) IfEach added in v0.0.4

func (slice Int32Slice) 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 (Int32Slice) IndexOf

func (slice Int32Slice) IndexOf(needle int32) int

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

func (Int32Slice) Map

func (slice Int32Slice) Map(f func(int32) int32)

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

func (Int32Slice) Reverse

func (slice Int32Slice) Reverse() Int32Slice

Reverse will reverse the order of the slice

func (Int32Slice) SortAsc

func (slice Int32Slice) SortAsc() Int32Slice

SortAsc will sort the slice in ascending order

func (Int32Slice) SortDesc

func (slice Int32Slice) SortDesc() Int32Slice

SortDesc will sort the slice in descending order

func (Int32Slice) TryEach added in v0.0.4

func (slice Int32Slice) 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 (Int32Slice) Unique

func (slice Int32Slice) Unique() Int32Slice

Unique filters out duplicate int32 values

func (Int32Slice) Value

func (slice Int32Slice) Value() []int32

Value returns the aliased []int32

type Int64Slice

type Int64Slice []int64

Int64Slice is the alias of []int64

func (Int64Slice) Chunk added in v0.0.5

func (slice Int64Slice) Chunk(size int) [][]int64

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

func (Int64Slice) Contains

func (slice Int64Slice) Contains(needle int64) bool

Contains returns true if the slice contains needle

func (Int64Slice) Each

func (slice Int64Slice) 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 (Int64Slice) Filter

func (slice Int64Slice) Filter(f func(int64) bool) Int64Slice

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

func (Int64Slice) IfEach added in v0.0.4

func (slice Int64Slice) 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 (Int64Slice) IndexOf

func (slice Int64Slice) IndexOf(needle int64) int

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

func (Int64Slice) Map

func (slice Int64Slice) Map(f func(int64) int64)

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

func (Int64Slice) Reverse

func (slice Int64Slice) Reverse() Int64Slice

Reverse will reverse the order of the slice

func (Int64Slice) SortAsc

func (slice Int64Slice) SortAsc() Int64Slice

SortAsc will sort the slice in ascending order

func (Int64Slice) SortDesc

func (slice Int64Slice) SortDesc() Int64Slice

SortDesc will sort the slice in descending order

func (Int64Slice) TryEach added in v0.0.4

func (slice Int64Slice) 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 (Int64Slice) Unique

func (slice Int64Slice) Unique() Int64Slice

Unique filters out duplicate int64 values

func (Int64Slice) Value

func (slice Int64Slice) Value() []int64

Value returns the aliased []int64

type Int8Slice

type Int8Slice []int8

Int8Slice is the alias of []int8

func (Int8Slice) Chunk added in v0.0.5

func (slice Int8Slice) Chunk(size int) [][]int8

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

func (Int8Slice) Contains

func (slice Int8Slice) Contains(needle int8) bool

Contains returns true if the slice contains needle

func (Int8Slice) Each

func (slice Int8Slice) 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 (Int8Slice) Filter

func (slice Int8Slice) Filter(f func(int8) bool) Int8Slice

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

func (Int8Slice) IfEach added in v0.0.4

func (slice Int8Slice) 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 (Int8Slice) IndexOf

func (slice Int8Slice) IndexOf(needle int8) int

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

func (Int8Slice) Map

func (slice Int8Slice) Map(f func(int8) int8)

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

func (Int8Slice) Reverse

func (slice Int8Slice) Reverse() Int8Slice

Reverse will reverse the order of the slice

func (Int8Slice) SortAsc

func (slice Int8Slice) SortAsc() Int8Slice

SortAsc will sort the slice in ascending order

func (Int8Slice) SortDesc

func (slice Int8Slice) SortDesc() Int8Slice

SortDesc will sort the slice in descending order

func (Int8Slice) TryEach added in v0.0.4

func (slice Int8Slice) 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 (Int8Slice) Unique

func (slice Int8Slice) Unique() Int8Slice

Unique filters out duplicate int8 values

func (Int8Slice) Value

func (slice Int8Slice) Value() []int8

Value returns the aliased []int8

type IntSlice

type IntSlice []int

IntSlice is the alias of []int

func (IntSlice) Chunk added in v0.0.5

func (slice IntSlice) Chunk(size int) [][]int

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

func (IntSlice) Contains

func (slice IntSlice) Contains(needle int) bool

Contains returns true if the slice contains needle

func (IntSlice) Each

func (slice IntSlice) 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 (IntSlice) Filter

func (slice IntSlice) Filter(f func(int) bool) IntSlice

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

func (IntSlice) IfEach added in v0.0.4

func (slice IntSlice) 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 (IntSlice) IndexOf

func (slice IntSlice) IndexOf(needle int) int

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

func (IntSlice) Map

func (slice IntSlice) Map(f func(int) int)

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

func (IntSlice) Reverse

func (slice IntSlice) Reverse() IntSlice

Reverse will reverse the order of the slice

func (IntSlice) SortAsc

func (slice IntSlice) SortAsc() IntSlice

SortAsc will sort the slice in ascending order

func (IntSlice) SortDesc

func (slice IntSlice) SortDesc() IntSlice

SortDesc will sort the slice in descending order

func (IntSlice) TryEach added in v0.0.4

func (slice IntSlice) 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 (IntSlice) Unique

func (slice IntSlice) Unique() IntSlice

Unique filters out duplicate int values

func (IntSlice) Value

func (slice IntSlice) Value() []int

Value returns the aliased []int

type StringSlice

type StringSlice []string

StringSlice is the alias of []string

func (StringSlice) Chunk added in v0.0.5

func (slice StringSlice) Chunk(size int) [][]string

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

func (StringSlice) Contains

func (slice StringSlice) Contains(needle string) bool

Contains returns true if the slice contains needle

func (StringSlice) Each

func (slice StringSlice) 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.

func (StringSlice) Filter

func (slice StringSlice) Filter(f func(string) bool) StringSlice

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

func (StringSlice) IfEach added in v0.0.4

func (slice StringSlice) 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 (StringSlice) IndexOf

func (slice StringSlice) IndexOf(needle string) int

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

func (StringSlice) Map

func (slice StringSlice) Map(f func(string) string)

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

func (StringSlice) Reverse

func (slice StringSlice) Reverse() StringSlice

Reverse will reverse the order of the slice

func (StringSlice) SortAsc

func (slice StringSlice) SortAsc() StringSlice

SortAsc will sort the slice in ascending order

func (StringSlice) SortDesc

func (slice StringSlice) SortDesc() StringSlice

SortDesc will sort the slice in descending order

func (StringSlice) TryEach added in v0.0.4

func (slice StringSlice) 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 (StringSlice) Unique

func (slice StringSlice) Unique() StringSlice

Unique filters out duplicate string values

func (StringSlice) Value

func (slice StringSlice) Value() []string

Value returns the aliased []string

type UInt16Slice

type UInt16Slice []uint16

UInt16Slice is the alias of []uint16

func (UInt16Slice) Chunk added in v0.0.5

func (slice UInt16Slice) Chunk(size int) [][]uint16

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

func (UInt16Slice) Contains

func (slice UInt16Slice) Contains(needle uint16) bool

Contains returns true if the slice contains needle

func (UInt16Slice) Each

func (slice UInt16Slice) 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 (UInt16Slice) Filter

func (slice UInt16Slice) Filter(f func(uint16) bool) UInt16Slice

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

func (UInt16Slice) IfEach added in v0.0.4

func (slice UInt16Slice) 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 (UInt16Slice) IndexOf

func (slice UInt16Slice) IndexOf(needle uint16) int

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

func (UInt16Slice) Map

func (slice UInt16Slice) Map(f func(uint16) uint16)

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

func (UInt16Slice) Reverse

func (slice UInt16Slice) Reverse() UInt16Slice

Reverse will reverse the order of the slice

func (UInt16Slice) SortAsc

func (slice UInt16Slice) SortAsc() UInt16Slice

SortAsc will sort the slice in ascending order

func (UInt16Slice) SortDesc

func (slice UInt16Slice) SortDesc() UInt16Slice

SortDesc will sort the slice in descending order

func (UInt16Slice) TryEach added in v0.0.4

func (slice UInt16Slice) 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 (UInt16Slice) Unique

func (slice UInt16Slice) Unique() UInt16Slice

Unique filters out duplicate uint16 values

func (UInt16Slice) Value

func (slice UInt16Slice) Value() []uint16

Value returns the aliased []uint16

type UInt32Slice

type UInt32Slice []uint32

UInt32Slice is the alias of []uint32

func (UInt32Slice) Chunk added in v0.0.5

func (slice UInt32Slice) Chunk(size int) [][]uint32

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

func (UInt32Slice) Contains

func (slice UInt32Slice) Contains(needle uint32) bool

Contains returns true if the slice contains needle

func (UInt32Slice) Each

func (slice UInt32Slice) 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 (UInt32Slice) Filter

func (slice UInt32Slice) Filter(f func(uint32) bool) UInt32Slice

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

func (UInt32Slice) IfEach added in v0.0.4

func (slice UInt32Slice) 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 (UInt32Slice) IndexOf

func (slice UInt32Slice) IndexOf(needle uint32) int

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

func (UInt32Slice) Map

func (slice UInt32Slice) Map(f func(uint32) uint32)

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

func (UInt32Slice) Reverse

func (slice UInt32Slice) Reverse() UInt32Slice

Reverse will reverse the order of the slice

func (UInt32Slice) SortAsc

func (slice UInt32Slice) SortAsc() UInt32Slice

SortAsc will sort the slice in ascending order

func (UInt32Slice) SortDesc

func (slice UInt32Slice) SortDesc() UInt32Slice

SortDesc will sort the slice in descending order

func (UInt32Slice) TryEach added in v0.0.4

func (slice UInt32Slice) 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 (UInt32Slice) Unique

func (slice UInt32Slice) Unique() UInt32Slice

Unique filters out duplicate uint32 values

func (UInt32Slice) Value

func (slice UInt32Slice) Value() []uint32

Value returns the aliased []uint32

type UInt64Slice

type UInt64Slice []uint64

UInt64Slice is the alias of []uint64

func (UInt64Slice) Chunk added in v0.0.5

func (slice UInt64Slice) Chunk(size int) [][]uint64

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

func (UInt64Slice) Contains

func (slice UInt64Slice) Contains(needle uint64) bool

Contains returns true if the slice contains needle

func (UInt64Slice) Each

func (slice UInt64Slice) 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 (UInt64Slice) Filter

func (slice UInt64Slice) Filter(f func(uint64) bool) UInt64Slice

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

func (UInt64Slice) IfEach added in v0.0.4

func (slice UInt64Slice) 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 (UInt64Slice) IndexOf

func (slice UInt64Slice) IndexOf(needle uint64) int

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

func (UInt64Slice) Map

func (slice UInt64Slice) Map(f func(uint64) uint64)

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

func (UInt64Slice) Reverse

func (slice UInt64Slice) Reverse() UInt64Slice

Reverse will reverse the order of the slice

func (UInt64Slice) SortAsc

func (slice UInt64Slice) SortAsc() UInt64Slice

SortAsc will sort the slice in ascending order

func (UInt64Slice) SortDesc

func (slice UInt64Slice) SortDesc() UInt64Slice

SortDesc will sort the slice in descending order

func (UInt64Slice) TryEach added in v0.0.4

func (slice UInt64Slice) 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 (UInt64Slice) Unique

func (slice UInt64Slice) Unique() UInt64Slice

Unique filters out duplicate uint64 values

func (UInt64Slice) Value

func (slice UInt64Slice) Value() []uint64

Value returns the aliased []uint64

type UInt8Slice

type UInt8Slice []uint8

UInt8Slice is the alias of []uint8

func (UInt8Slice) Chunk added in v0.0.5

func (slice UInt8Slice) Chunk(size int) [][]uint8

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

func (UInt8Slice) Contains

func (slice UInt8Slice) Contains(needle uint8) bool

Contains returns true if the slice contains needle

func (UInt8Slice) Each

func (slice UInt8Slice) 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 (UInt8Slice) Filter

func (slice UInt8Slice) Filter(f func(uint8) bool) UInt8Slice

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

func (UInt8Slice) IfEach added in v0.0.4

func (slice UInt8Slice) 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 (UInt8Slice) IndexOf

func (slice UInt8Slice) IndexOf(needle uint8) int

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

func (UInt8Slice) Map

func (slice UInt8Slice) Map(f func(uint8) uint8)

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

func (UInt8Slice) Reverse

func (slice UInt8Slice) Reverse() UInt8Slice

Reverse will reverse the order of the slice

func (UInt8Slice) SortAsc

func (slice UInt8Slice) SortAsc() UInt8Slice

SortAsc will sort the slice in ascending order

func (UInt8Slice) SortDesc

func (slice UInt8Slice) SortDesc() UInt8Slice

SortDesc will sort the slice in descending order

func (UInt8Slice) TryEach added in v0.0.4

func (slice UInt8Slice) 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 (UInt8Slice) Unique

func (slice UInt8Slice) Unique() UInt8Slice

Unique filters out duplicate uint8 values

func (UInt8Slice) Value

func (slice UInt8Slice) Value() []uint8

Value returns the aliased []uint8

type UIntPtrSlice

type UIntPtrSlice []uintptr

UIntPtrSlice is the alias of []uintptr

func (UIntPtrSlice) Chunk added in v0.0.5

func (slice UIntPtrSlice) Chunk(size int) [][]uintptr

Chunk will divide the slice of uintptr into smaller slices defined by chunk length

func (UIntPtrSlice) Contains

func (slice UIntPtrSlice) Contains(needle uintptr) bool

Contains returns true if the slice contains needle

func (UIntPtrSlice) Each

func (slice UIntPtrSlice) Each(f func(uintptr))

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

func (UIntPtrSlice) Filter

func (slice UIntPtrSlice) Filter(f func(uintptr) bool) UIntPtrSlice

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

func (UIntPtrSlice) IfEach added in v0.0.4

func (slice UIntPtrSlice) IfEach(f func(uintptr) bool) (int, bool)

IfEach will apply a function to each uintptr 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 (UIntPtrSlice) IndexOf

func (slice UIntPtrSlice) IndexOf(needle uintptr) int

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

func (UIntPtrSlice) Map

func (slice UIntPtrSlice) Map(f func(uintptr) uintptr)

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

func (UIntPtrSlice) Reverse

func (slice UIntPtrSlice) Reverse() UIntPtrSlice

Reverse will reverse the order of the slice

func (UIntPtrSlice) SortAsc

func (slice UIntPtrSlice) SortAsc() UIntPtrSlice

SortAsc will sort the slice in ascending order

func (UIntPtrSlice) SortDesc

func (slice UIntPtrSlice) SortDesc() UIntPtrSlice

SortDesc will sort the slice in descending order

func (UIntPtrSlice) TryEach added in v0.0.4

func (slice UIntPtrSlice) TryEach(f func(uintptr) error) (int, error)

TryEach will apply a function to each uintptr 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 (UIntPtrSlice) Unique

func (slice UIntPtrSlice) Unique() UIntPtrSlice

Unique filters out duplicate uintptr values

func (UIntPtrSlice) Value

func (slice UIntPtrSlice) Value() []uintptr

Value returns the aliased []uintptr

type UIntSlice

type UIntSlice []uint

UIntSlice is the alias of []uint

func (UIntSlice) Chunk added in v0.0.5

func (slice UIntSlice) Chunk(size int) [][]uint

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

func (UIntSlice) Contains

func (slice UIntSlice) Contains(needle uint) bool

Contains returns true if the slice contains needle

func (UIntSlice) Each

func (slice UIntSlice) 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 (UIntSlice) Filter

func (slice UIntSlice) Filter(f func(uint) bool) UIntSlice

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

func (UIntSlice) IfEach added in v0.0.4

func (slice UIntSlice) 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 (UIntSlice) IndexOf

func (slice UIntSlice) IndexOf(needle uint) int

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

func (UIntSlice) Map

func (slice UIntSlice) Map(f func(uint) uint)

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

func (UIntSlice) Reverse

func (slice UIntSlice) Reverse() UIntSlice

Reverse will reverse the order of the slice

func (UIntSlice) SortAsc

func (slice UIntSlice) SortAsc() UIntSlice

SortAsc will sort the slice in ascending order

func (UIntSlice) SortDesc

func (slice UIntSlice) SortDesc() UIntSlice

SortDesc will sort the slice in descending order

func (UIntSlice) TryEach added in v0.0.4

func (slice UIntSlice) 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 (UIntSlice) Unique

func (slice UIntSlice) Unique() UIntSlice

Unique filters out duplicate uint values

func (UIntSlice) Value

func (slice UIntSlice) Value() []uint

Value returns the aliased []uint

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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