slice

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: MIT Imports: 2 Imported by: 4

README

slice

slice utils for golang.

Build Status Coverage Status Go Report Card Documentation

Install

$ go get github.com/lovego/slice

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendIfNo

func AppendIfNo(slice interface{}, targets ...interface{}) interface{}

AppendIfNo append value in targets to slice if slice has no this value.

Example
var slice = []T{{3, "c"}, {}, {2, "b"}, {}, {9, "f"}}
fmt.Println(AppendIfNo(slice, T{2, "b"}))
fmt.Println(AppendIfNo(slice, T{}))
fmt.Println(AppendIfNo(slice, T{}, T{4, "d"}))
Output:

[{3 c} {0 } {2 b} {0 } {9 f}]
[{3 c} {0 } {2 b} {0 } {9 f}]
[{3 c} {0 } {2 b} {0 } {9 f} {4 d}]

func AppendIfNoBool added in v0.1.0

func AppendIfNoBool(slice []bool, targets ...bool) []bool
Example
fmt.Println(AppendIfNoBool(nil, true))
fmt.Println(AppendIfNoBool([]bool{true, false}, true))
fmt.Println(AppendIfNoBool([]bool{true, true}, true, false))
Output:

[true]
[true false]
[true true false]

func AppendIfNoInt

func AppendIfNoInt(slice []int, targets ...int) []int
Example
fmt.Println(AppendIfNoInt(nil, 1))
fmt.Println(AppendIfNoInt([]int{1, 2}, 1))
fmt.Println(AppendIfNoInt([]int{1, 2}, 2, 3))
Output:

[1]
[1 2]
[1 2 3]

func AppendIfNoInt16 added in v0.0.4

func AppendIfNoInt16(slice []int16, targets ...int16) []int16
Example
fmt.Println(AppendIfNoInt16(nil, 1))
fmt.Println(AppendIfNoInt16([]int16{1, 2}, 1))
fmt.Println(AppendIfNoInt16([]int16{1, 2}, 2, 3))
Output:

[1]
[1 2]
[1 2 3]

func AppendIfNoInt32 added in v0.0.4

func AppendIfNoInt32(slice []int32, targets ...int32) []int32
Example
fmt.Println(AppendIfNoInt32(nil, 1))
fmt.Println(AppendIfNoInt32([]int32{1, 2}, 1))
fmt.Println(AppendIfNoInt32([]int32{1, 2}, 2, 3))
Output:

[1]
[1 2]
[1 2 3]

func AppendIfNoInt64

func AppendIfNoInt64(slice []int64, targets ...int64) []int64
Example
fmt.Println(AppendIfNoInt64(nil, 1))
fmt.Println(AppendIfNoInt64([]int64{1, 2}, 1))
fmt.Println(AppendIfNoInt64([]int64{1, 2}, 2, 3))
Output:

[1]
[1 2]
[1 2 3]

func AppendIfNoInt8 added in v0.0.4

func AppendIfNoInt8(slice []int8, targets ...int8) []int8
Example
fmt.Println(AppendIfNoInt8(nil, 1))
fmt.Println(AppendIfNoInt8([]int8{1, 2}, 1))
fmt.Println(AppendIfNoInt8([]int8{1, 2}, 2, 3))
Output:

[1]
[1 2]
[1 2 3]

func AppendIfNoInterface added in v0.0.4

func AppendIfNoInterface(slice []interface{}, targets ...interface{}) []interface{}
Example
var slice = []interface{}{3, "c", false, 2, "b"}
fmt.Println(AppendIfNoInterface(slice, 3, "b"))
fmt.Println(AppendIfNoInterface(slice, false, 2))
fmt.Println(AppendIfNoInterface(slice, "c", 4, "d"))
Output:

[3 c false 2 b]
[3 c false 2 b]
[3 c false 2 b 4 d]

func AppendIfNoString

func AppendIfNoString(slice []string, targets ...string) []string
Example
fmt.Println(AppendIfNoString(nil, "a"))
fmt.Println(AppendIfNoString([]string{"a", "b"}, "a"))
fmt.Println(AppendIfNoString([]string{"a", "b"}, "b", "c"))
Output:

[a]
[a b]
[a b c]

func AppendIfNoUint added in v0.0.4

func AppendIfNoUint(slice []uint, targets ...uint) []uint
Example
fmt.Println(AppendIfNoUint(nil, 1))
fmt.Println(AppendIfNoUint([]uint{1, 2}, 1))
fmt.Println(AppendIfNoUint([]uint{1, 2}, 2, 3))
Output:

[1]
[1 2]
[1 2 3]

func AppendIfNoUint16 added in v0.0.4

func AppendIfNoUint16(slice []uint16, targets ...uint16) []uint16
Example
fmt.Println(AppendIfNoUint16(nil, 1))
fmt.Println(AppendIfNoUint16([]uint16{1, 2}, 1))
fmt.Println(AppendIfNoUint16([]uint16{1, 2}, 2, 3))
Output:

[1]
[1 2]
[1 2 3]

func AppendIfNoUint32 added in v0.0.4

func AppendIfNoUint32(slice []uint32, targets ...uint32) []uint32
Example
fmt.Println(AppendIfNoUint32(nil, 1))
fmt.Println(AppendIfNoUint32([]uint32{1, 2}, 1))
fmt.Println(AppendIfNoUint32([]uint32{1, 2}, 2, 3))
Output:

[1]
[1 2]
[1 2 3]

func AppendIfNoUint64 added in v0.0.4

func AppendIfNoUint64(slice []uint64, targets ...uint64) []uint64
Example
fmt.Println(AppendIfNoUint64(nil, 1))
fmt.Println(AppendIfNoUint64([]uint64{1, 2}, 1))
fmt.Println(AppendIfNoUint64([]uint64{1, 2}, 2, 3))
Output:

[1]
[1 2]
[1 2 3]

func AppendIfNoUint8 added in v0.0.4

func AppendIfNoUint8(slice []uint8, targets ...uint8) []uint8
Example
fmt.Println(AppendIfNoUint8(nil, 1))
fmt.Println(AppendIfNoUint8([]uint8{1, 2}, 1))
fmt.Println(AppendIfNoUint8([]uint8{1, 2}, 2, 3))
Output:

[1]
[1 2]
[1 2 3]

func AppendIfNoValue added in v0.0.4

func AppendIfNoValue(slice reflect.Value, targets ...interface{}) reflect.Value
Example
var slice = reflect.ValueOf([]T{{3, "c"}, {}, {2, "b"}, {}, {9, "f"}})
fmt.Println(AppendIfNoValue(slice, T{2, "b"}))
fmt.Println(AppendIfNoValue(slice, T{}))
fmt.Println(AppendIfNoValue(slice, T{}, T{4, "d"}))
Output:

[{3 c} {0 } {2 b} {0 } {9 f}]
[{3 c} {0 } {2 b} {0 } {9 f}]
[{3 c} {0 } {2 b} {0 } {9 f} {4 d}]

func Contains added in v0.0.4

func Contains(length int, fun func(int) bool) bool
Example
fmt.Println(Contains(0, func(i int) bool { return true }))
var slice = []T{{3, "c"}, {}, {2, "b"}, {9, "f"}}
var length = len(slice)
fmt.Println(Contains(length, func(i int) bool { return slice[i] == T{} }))
fmt.Println(Contains(length, func(i int) bool { return slice[i] == T{2, "b"} }))
fmt.Println(Contains(length, func(i int) bool { return slice[i] == T{2, "c"} }))
Output:

false
true
true
false

func ContainsAllBool added in v0.1.0

func ContainsAllBool(slice []bool, targets ...bool) bool
Example
fmt.Println(ContainsAllBool([]bool{true, false}))
fmt.Println(ContainsAllBool([]bool{true, false}, true))
fmt.Println(ContainsAllBool([]bool{true, false}, false, true))
fmt.Println(ContainsAllBool([]bool{true, true}, true, false))
fmt.Println(ContainsAllBool([]bool{false}, true, false))
Output:

true
true
true
false
false

func ContainsAllGeneric added in v0.0.5

func ContainsAllGeneric(slice interface{}, targets ...interface{}) bool
Example
fmt.Println(ContainsAllGeneric(nil))
fmt.Println(ContainsAllGeneric(nil, T{}))
fmt.Println(ContainsAllGeneric([]bool{}))
fmt.Println(ContainsAllGeneric([]bool{}, "xx"))
var slice = []T{{3, "c"}, {}, {2, "b"}, {9, "f"}}
fmt.Println(ContainsAllGeneric(slice))
fmt.Println(ContainsAllGeneric(slice, T{}))
fmt.Println(ContainsAllGeneric(slice, T{}, T{2, "b"}))
fmt.Println(ContainsAllGeneric(slice, T{2, "c"}))
fmt.Println(ContainsAllGeneric(slice, 2))
Output:

true
false
true
false
true
true
true
false
false

func ContainsAllInt added in v0.0.4

func ContainsAllInt(slice []int, targets ...int) bool
Example
fmt.Println(ContainsAllInt([]int{1, 2}))
fmt.Println(ContainsAllInt([]int{1, 2}, 1))
fmt.Println(ContainsAllInt([]int{1, 2}, 2, 1))
fmt.Println(ContainsAllInt([]int{1, 2}, 2, 3))
fmt.Println(ContainsAllInt([]int{1, 2}, 3, 4))
Output:

true
true
true
false
false

func ContainsAllInt16 added in v0.0.4

func ContainsAllInt16(slice []int16, targets ...int16) bool
Example
fmt.Println(ContainsAllInt16([]int16{1, 2}))
fmt.Println(ContainsAllInt16([]int16{1, 2}, 1))
fmt.Println(ContainsAllInt16([]int16{1, 2}, 2, 1))
fmt.Println(ContainsAllInt16([]int16{1, 2}, 2, 3))
fmt.Println(ContainsAllInt16([]int16{1, 2}, 3, 4))
Output:

true
true
true
false
false

func ContainsAllInt32 added in v0.0.4

func ContainsAllInt32(slice []int32, targets ...int32) bool
Example
fmt.Println(ContainsAllInt32([]int32{1, 2}))
fmt.Println(ContainsAllInt32([]int32{1, 2}, 1))
fmt.Println(ContainsAllInt32([]int32{1, 2}, 2, 1))
fmt.Println(ContainsAllInt32([]int32{1, 2}, 2, 3))
fmt.Println(ContainsAllInt32([]int32{1, 2}, 3, 4))
Output:

true
true
true
false
false

func ContainsAllInt64

func ContainsAllInt64(slice []int64, targets ...int64) bool
Example
fmt.Println(ContainsAllInt64([]int64{1, 2}))
fmt.Println(ContainsAllInt64([]int64{1, 2}, 1))
fmt.Println(ContainsAllInt64([]int64{1, 2}, 2, 1))
fmt.Println(ContainsAllInt64([]int64{1, 2}, 2, 3))
fmt.Println(ContainsAllInt64([]int64{1, 2}, 3, 4))
Output:

true
true
true
false
false

func ContainsAllInt8 added in v0.0.4

func ContainsAllInt8(slice []int8, targets ...int8) bool
Example
fmt.Println(ContainsAllInt8([]int8{1, 2}))
fmt.Println(ContainsAllInt8([]int8{1, 2}, 1))
fmt.Println(ContainsAllInt8([]int8{1, 2}, 2, 1))
fmt.Println(ContainsAllInt8([]int8{1, 2}, 2, 3))
fmt.Println(ContainsAllInt8([]int8{1, 2}, 3, 4))
Output:

true
true
true
false
false

func ContainsAllInterface added in v0.0.4

func ContainsAllInterface(slice []interface{}, targets ...interface{}) bool
Example
var slice = []interface{}{`1`, 2, `3`}
fmt.Println(ContainsAllInterface(slice, 2, `3`))
fmt.Println(ContainsAllInterface(slice, `2`, `3`))
Output:

true
false

func ContainsAllString

func ContainsAllString(slice []string, targets ...string) bool
Example
fmt.Println(ContainsAllString([]string{"1", "2"}))
fmt.Println(ContainsAllString([]string{"1", "2"}, "1"))
fmt.Println(ContainsAllString([]string{"1", "2"}, "2", "1"))
fmt.Println(ContainsAllString([]string{"1", "2"}, "2", "3"))
fmt.Println(ContainsAllString([]string{"1", "2"}, "3", "4"))
Output:

true
true
true
false
false

func ContainsAllUint added in v0.0.4

func ContainsAllUint(slice []uint, targets ...uint) bool
Example
fmt.Println(ContainsAllUint([]uint{1, 2}))
fmt.Println(ContainsAllUint([]uint{1, 2}, 1))
fmt.Println(ContainsAllUint([]uint{1, 2}, 2, 1))
fmt.Println(ContainsAllUint([]uint{1, 2}, 2, 3))
fmt.Println(ContainsAllUint([]uint{1, 2}, 3, 4))
Output:

true
true
true
false
false

func ContainsAllUint16 added in v0.0.4

func ContainsAllUint16(slice []uint16, targets ...uint16) bool
Example
fmt.Println(ContainsAllUint16([]uint16{1, 2}))
fmt.Println(ContainsAllUint16([]uint16{1, 2}, 1))
fmt.Println(ContainsAllUint16([]uint16{1, 2}, 2, 1))
fmt.Println(ContainsAllUint16([]uint16{1, 2}, 2, 3))
fmt.Println(ContainsAllUint16([]uint16{1, 2}, 3, 4))
Output:

true
true
true
false
false

func ContainsAllUint32 added in v0.0.4

func ContainsAllUint32(slice []uint32, targets ...uint32) bool
Example
fmt.Println(ContainsAllUint32([]uint32{1, 2}))
fmt.Println(ContainsAllUint32([]uint32{1, 2}, 1))
fmt.Println(ContainsAllUint32([]uint32{1, 2}, 2, 1))
fmt.Println(ContainsAllUint32([]uint32{1, 2}, 2, 3))
fmt.Println(ContainsAllUint32([]uint32{1, 2}, 3, 4))
Output:

true
true
true
false
false

func ContainsAllUint64 added in v0.0.4

func ContainsAllUint64(slice []uint64, targets ...uint64) bool
Example
fmt.Println(ContainsAllUint64([]uint64{1, 2}))
fmt.Println(ContainsAllUint64([]uint64{1, 2}, 1))
fmt.Println(ContainsAllUint64([]uint64{1, 2}, 2, 1))
fmt.Println(ContainsAllUint64([]uint64{1, 2}, 2, 3))
fmt.Println(ContainsAllUint64([]uint64{1, 2}, 3, 4))
Output:

true
true
true
false
false

func ContainsAllUint8 added in v0.0.4

func ContainsAllUint8(slice []uint8, targets ...uint8) bool
Example
fmt.Println(ContainsAllUint8([]uint8{1, 2}))
fmt.Println(ContainsAllUint8([]uint8{1, 2}, 1))
fmt.Println(ContainsAllUint8([]uint8{1, 2}, 2, 1))
fmt.Println(ContainsAllUint8([]uint8{1, 2}, 2, 3))
fmt.Println(ContainsAllUint8([]uint8{1, 2}, 3, 4))
Output:

true
true
true
false
false

func ContainsAllValue added in v0.0.4

func ContainsAllValue(slice reflect.Value, targets ...interface{}) bool
Example
var slice = reflect.ValueOf([]interface{}{`1`, 2, `3`})
fmt.Println(ContainsAllValue(slice, 2, `3`))
fmt.Println(ContainsAllValue(slice, `2`, `3`))
fmt.Println(ContainsAllValue(reflect.ValueOf([]int{}), 2))
Output:

true
false
false

func ContainsAnyBool added in v0.1.0

func ContainsAnyBool(slice []bool, targets ...bool) bool
Example
fmt.Println(ContainsAnyBool(nil))
fmt.Println(ContainsAnyBool(nil, false))
fmt.Println(ContainsAnyBool([]bool{true, false}))
fmt.Println(ContainsAnyBool([]bool{true, true}, false))
fmt.Println(ContainsAnyBool([]bool{true, false}, false))
Output:

false
false
false
false
true

func ContainsAnyGeneric added in v0.0.5

func ContainsAnyGeneric(slice interface{}, targets ...interface{}) bool
Example
fmt.Println(ContainsAnyGeneric(nil))
fmt.Println(ContainsAnyGeneric(nil, T{}))
fmt.Println(ContainsAnyGeneric([]bool{}))
fmt.Println(ContainsAnyGeneric([]bool{}, "xx"))
var slice = []T{{3, "c"}, {}, {2, "b"}, {9, "f"}}
fmt.Println(ContainsAnyGeneric(slice))
fmt.Println(ContainsAnyGeneric(slice, T{}))
fmt.Println(ContainsAnyGeneric(slice, T{}, T{2, "b"}))
fmt.Println(ContainsAnyGeneric(slice, T{2, "c"}, T{}))
fmt.Println(ContainsAnyGeneric(slice, 2))
Output:

false
false
false
false
false
true
true
true
false

func ContainsAnyInt added in v0.0.4

func ContainsAnyInt(slice []int, targets ...int) bool
Example
fmt.Println(ContainsAnyInt(nil))
fmt.Println(ContainsAnyInt(nil, 0))
var slice = []int{1, 2, 3}
fmt.Println(ContainsAnyInt(slice))
fmt.Println(ContainsAnyInt(slice, 3))
fmt.Println(ContainsAnyInt(slice, 0, 4))
Output:

false
false
false
true
false

func ContainsAnyInt16 added in v0.0.4

func ContainsAnyInt16(slice []int16, targets ...int16) bool
Example
fmt.Println(ContainsAnyInt16(nil))
fmt.Println(ContainsAnyInt16(nil, 0))
var slice = []int16{1, 2, 3}
fmt.Println(ContainsAnyInt16(slice))
fmt.Println(ContainsAnyInt16(slice, 3))
fmt.Println(ContainsAnyInt16(slice, 0, 4))
Output:

false
false
false
true
false

func ContainsAnyInt32 added in v0.0.4

func ContainsAnyInt32(slice []int32, targets ...int32) bool
Example
fmt.Println(ContainsAnyInt32(nil))
fmt.Println(ContainsAnyInt32(nil, 0))
var slice = []int32{1, 2, 3}
fmt.Println(ContainsAnyInt32(slice))
fmt.Println(ContainsAnyInt32(slice, 3))
fmt.Println(ContainsAnyInt32(slice, 0, 4))
Output:

false
false
false
true
false

func ContainsAnyInt64 added in v0.0.4

func ContainsAnyInt64(slice []int64, targets ...int64) bool
Example
fmt.Println(ContainsAnyInt64(nil))
fmt.Println(ContainsAnyInt64(nil, 0))
var slice = []int64{1, 2, 3}
fmt.Println(ContainsAnyInt64(slice))
fmt.Println(ContainsAnyInt64(slice, 3))
fmt.Println(ContainsAnyInt64(slice, 0, 4))
Output:

false
false
false
true
false

func ContainsAnyInt8 added in v0.0.4

func ContainsAnyInt8(slice []int8, targets ...int8) bool
Example
fmt.Println(ContainsAnyInt8(nil))
fmt.Println(ContainsAnyInt8(nil, 0))
var slice = []int8{1, 2, 3}
fmt.Println(ContainsAnyInt8(slice))
fmt.Println(ContainsAnyInt8(slice, 3))
fmt.Println(ContainsAnyInt8(slice, 0, 4))
Output:

false
false
false
true
false

func ContainsAnyInterface added in v0.0.4

func ContainsAnyInterface(slice []interface{}, targets ...interface{}) bool
Example
fmt.Println(ContainsAnyInterface(nil))
var slice = []interface{}{`1`, 2, `3`}
fmt.Println(ContainsAnyInterface(slice, 2, `3`))
fmt.Println(ContainsAnyInterface(slice, `2`, `3`))
fmt.Println(ContainsAnyInterface(slice, `x`))
Output:

false
true
true
false

func ContainsAnyString

func ContainsAnyString(slice []string, targets ...string) bool
Example
fmt.Println(ContainsAnyString(nil))
fmt.Println(ContainsAnyString(nil, `x`))
var slice = []string{`1`, `2`, `3`}
fmt.Println(ContainsAnyString(slice))
fmt.Println(ContainsAnyString(slice, `x`, `0`))
fmt.Println(ContainsAnyString(slice, `x`, `2`))
Output:

false
false
false
false
true

func ContainsAnyUint added in v0.0.4

func ContainsAnyUint(slice []uint, targets ...uint) bool
Example
fmt.Println(ContainsAnyUint(nil))
fmt.Println(ContainsAnyUint(nil, 0))
var slice = []uint{1, 2, 3}
fmt.Println(ContainsAnyUint(slice))
fmt.Println(ContainsAnyUint(slice, 3))
fmt.Println(ContainsAnyUint(slice, 0, 4))
Output:

false
false
false
true
false

func ContainsAnyUint16 added in v0.0.4

func ContainsAnyUint16(slice []uint16, targets ...uint16) bool
Example
fmt.Println(ContainsAnyUint16(nil))
fmt.Println(ContainsAnyUint16(nil, 0))
var slice = []uint16{1, 2, 3}
fmt.Println(ContainsAnyUint16(slice))
fmt.Println(ContainsAnyUint16(slice, 3))
fmt.Println(ContainsAnyUint16(slice, 0, 4))
Output:

false
false
false
true
false

func ContainsAnyUint32 added in v0.0.4

func ContainsAnyUint32(slice []uint32, targets ...uint32) bool
Example
fmt.Println(ContainsAnyUint32(nil))
fmt.Println(ContainsAnyUint32(nil, 0))
var slice = []uint32{1, 2, 3}
fmt.Println(ContainsAnyUint32(slice))
fmt.Println(ContainsAnyUint32(slice, 3))
fmt.Println(ContainsAnyUint32(slice, 0, 4))
Output:

false
false
false
true
false

func ContainsAnyUint64 added in v0.0.4

func ContainsAnyUint64(slice []uint64, targets ...uint64) bool
Example
fmt.Println(ContainsAnyUint64(nil))
fmt.Println(ContainsAnyUint64(nil, 0))
var slice = []uint64{1, 2, 3}
fmt.Println(ContainsAnyUint64(slice))
fmt.Println(ContainsAnyUint64(slice, 3))
fmt.Println(ContainsAnyUint64(slice, 0, 4))
Output:

false
false
false
true
false

func ContainsAnyUint8 added in v0.0.4

func ContainsAnyUint8(slice []uint8, targets ...uint8) bool
Example
fmt.Println(ContainsAnyUint8(nil))
fmt.Println(ContainsAnyUint8(nil, 0))
var slice = []uint8{1, 2, 3}
fmt.Println(ContainsAnyUint8(slice))
fmt.Println(ContainsAnyUint8(slice, 3))
fmt.Println(ContainsAnyUint8(slice, 0, 4))
Output:

false
false
false
true
false

func ContainsAnyValue added in v0.0.4

func ContainsAnyValue(slice reflect.Value, targets ...interface{}) bool
Example
fmt.Println(ContainsAnyValue(reflect.ValueOf([]int{}), 4))
var slice = reflect.ValueOf([]interface{}{`1`, 2, `3`})
fmt.Println(ContainsAnyValue(slice, 2, `3`))
fmt.Println(ContainsAnyValue(slice, `x`, `3`))
fmt.Println(ContainsAnyValue(slice, `x`, 4))
Output:

false
true
true
false

func ContainsBool added in v0.0.9

func ContainsBool(slice []bool, target bool) bool
Example
var slice = []bool{true, false, true}
fmt.Println(ContainsBool(slice, false))
fmt.Println(ContainsBool(slice, true))
fmt.Println(ContainsBool([]bool{true}, false))
Output:

true
true
false

func ContainsGeneric added in v0.0.5

func ContainsGeneric(slice interface{}, target interface{}) bool
Example
fmt.Println(ContainsGeneric(nil, T{}))
var slice = []T{{3, "c"}, {}, {2, "b"}, {9, "f"}}
fmt.Println(ContainsGeneric(slice, T{}))
fmt.Println(ContainsGeneric(slice, T{2, "b"}))
fmt.Println(ContainsGeneric(slice, T{2, "c"}))
fmt.Println(ContainsGeneric(slice, 2))
Output:

false
true
true
false
false

func ContainsInt

func ContainsInt(slice []int, target int) bool
Example
var slice = []int{1, 2, 3}
fmt.Println(ContainsInt(slice, 2))
fmt.Println(ContainsInt(slice, 4))
Output:

true
false

func ContainsInt16 added in v0.0.4

func ContainsInt16(slice []int16, target int16) bool
Example
var slice = []int16{1, 2, 3}
fmt.Println(ContainsInt16(slice, 2))
fmt.Println(ContainsInt16(slice, 4))
Output:

true
false

func ContainsInt32 added in v0.0.4

func ContainsInt32(slice []int32, target int32) bool
Example
var slice = []int32{1, 2, 3}
fmt.Println(ContainsInt32(slice, 2))
fmt.Println(ContainsInt32(slice, 4))
Output:

true
false

func ContainsInt64

func ContainsInt64(slice []int64, target int64) bool
Example
var slice = []int64{1, 2, 3}
fmt.Println(ContainsInt64(slice, 2))
fmt.Println(ContainsInt64(slice, 4))
Output:

true
false

func ContainsInt8

func ContainsInt8(slice []int8, target int8) bool
Example
var slice = []int8{1, 2, 3}
fmt.Println(ContainsInt8(slice, 2))
fmt.Println(ContainsInt8(slice, 4))
Output:

true
false

func ContainsInterface added in v0.0.4

func ContainsInterface(slice []interface{}, target interface{}) bool
Example
var slice = []interface{}{`1`, 2, `3`}
fmt.Println(ContainsInterface(slice, 2))
fmt.Println(ContainsInterface(slice, `2`))
Output:

true
false

func ContainsString

func ContainsString(slice []string, target string) bool
Example
var slice = []string{`1`, `2`, `3`}
fmt.Println(ContainsString(slice, `2`))
fmt.Println(ContainsString(slice, `4`))
Output:

true
false

func ContainsUint added in v0.0.4

func ContainsUint(slice []uint, target uint) bool
Example
var slice = []uint{1, 2, 3}
fmt.Println(ContainsUint(slice, 2))
fmt.Println(ContainsUint(slice, 4))
Output:

true
false

func ContainsUint16 added in v0.0.4

func ContainsUint16(slice []uint16, target uint16) bool
Example
var slice = []uint16{1, 2, 3}
fmt.Println(ContainsUint16(slice, 2))
fmt.Println(ContainsUint16(slice, 4))
Output:

true
false

func ContainsUint32 added in v0.0.4

func ContainsUint32(slice []uint32, target uint32) bool
Example
var slice = []uint32{1, 2, 3}
fmt.Println(ContainsUint32(slice, 2))
fmt.Println(ContainsUint32(slice, 4))
Output:

true
false

func ContainsUint64 added in v0.0.4

func ContainsUint64(slice []uint64, target uint64) bool
Example
var slice = []uint64{1, 2, 3}
fmt.Println(ContainsUint64(slice, 2))
fmt.Println(ContainsUint64(slice, 4))
Output:

true
false

func ContainsUint8 added in v0.0.4

func ContainsUint8(slice []uint8, target uint8) bool
Example
var slice = []uint8{1, 2, 3}
fmt.Println(ContainsUint8(slice, 2))
fmt.Println(ContainsUint8(slice, 4))
Output:

true
false

func ContainsValue added in v0.0.4

func ContainsValue(slice reflect.Value, target interface{}) bool
Example
var slice = reflect.ValueOf([]interface{}{`1`, 2, `3`})
fmt.Println(ContainsValue(slice, 2))
fmt.Println(ContainsValue(slice, `2`))
fmt.Println(ContainsValue(reflect.ValueOf([]int{}), 2))
Output:

true
false
false

func Index

func Index(length int, fun func(int) bool) int
Example
fmt.Println(Index(0, func(i int) bool { return true }))
var slice = []T{{3, "c"}, {}, {2, "b"}, {9, "f"}}
var length = len(slice)
fmt.Println(Index(length, func(i int) bool { return slice[i] == T{2, "c"} }))
fmt.Println(Index(length, func(i int) bool { return slice[i] == T{2, "b"} }))
Output:

-1
-1
2

func IndexBool added in v0.0.9

func IndexBool(slice []bool, target bool) int
Example
slice := []bool{true, false, true}
fmt.Println(IndexBool(nil, false))
fmt.Println(IndexBool(slice, true))
fmt.Println(IndexBool(slice, false))
Output:

-1
0
1

func IndexGeneric added in v0.0.5

func IndexGeneric(slice interface{}, target interface{}) int
Example
var slice = []T{{3, "c"}, {}, {2, "b"}, {9, "f"}}
fmt.Println(IndexGeneric(nil, 3))
fmt.Println(IndexGeneric([]int(nil), 3))
fmt.Println(IndexGeneric(slice, 3))
fmt.Println(IndexGeneric(slice, T{2, "c"}))
fmt.Println(IndexGeneric(slice, T{2, "b"}))
Output:

-1
-1
-1
-1
2

func IndexInt

func IndexInt(slice []int, target int) int
Example
slice := []int{1, 2, 3}
fmt.Println(IndexInt(nil, 3))
fmt.Println(IndexInt(slice, 0))
fmt.Println(IndexInt(slice, 1))
fmt.Println(IndexInt(slice, 3))
Output:

-1
-1
0
2

func IndexInt16 added in v0.0.4

func IndexInt16(slice []int16, target int16) int
Example
slice := []int16{1, 2, 3}
fmt.Println(IndexInt16(nil, 3))
fmt.Println(IndexInt16(slice, 0))
fmt.Println(IndexInt16(slice, 1))
fmt.Println(IndexInt16(slice, 3))
Output:

-1
-1
0
2

func IndexInt32 added in v0.0.4

func IndexInt32(slice []int32, target int32) int
Example
slice := []int32{1, 2, 3}
fmt.Println(IndexInt32(nil, 3))
fmt.Println(IndexInt32(slice, 0))
fmt.Println(IndexInt32(slice, 1))
fmt.Println(IndexInt32(slice, 3))
Output:

-1
-1
0
2

func IndexInt64

func IndexInt64(slice []int64, target int64) int
Example
slice := []int64{1, 2, 3}
fmt.Println(IndexInt64(nil, 3))
fmt.Println(IndexInt64(slice, 0))
fmt.Println(IndexInt64(slice, 1))
fmt.Println(IndexInt64(slice, 3))
Output:

-1
-1
0
2

func IndexInt8 added in v0.0.4

func IndexInt8(slice []int8, target int8) int
Example
slice := []int8{1, 2, 3}
fmt.Println(IndexInt8(nil, 3))
fmt.Println(IndexInt8(slice, 0))
fmt.Println(IndexInt8(slice, 1))
fmt.Println(IndexInt8(slice, 3))
Output:

-1
-1
0
2

func IndexInterface added in v0.0.4

func IndexInterface(slice []interface{}, target interface{}) int
Example
slice := []interface{}{true, `1`, 2, `3`}
fmt.Println(IndexInterface(nil, `3`))
fmt.Println(IndexInterface(slice, 0))
fmt.Println(IndexInterface(slice, `2`))
fmt.Println(IndexInterface(slice, true))
fmt.Println(IndexInterface(slice, 2))
Output:

-1
-1
-1
0
2

func IndexString

func IndexString(slice []string, target string) int
Example
slice := []string{`1`, `2`, `3`}
fmt.Println(IndexString(nil, `3`))
fmt.Println(IndexString(slice, `0`))
fmt.Println(IndexString(slice, `1`))
fmt.Println(IndexString(slice, `3`))
Output:

-1
-1
0
2

func IndexUint added in v0.0.4

func IndexUint(slice []uint, target uint) int
Example
slice := []uint{1, 2, 3}
fmt.Println(IndexUint(nil, 3))
fmt.Println(IndexUint(slice, 0))
fmt.Println(IndexUint(slice, 1))
fmt.Println(IndexUint(slice, 3))
Output:

-1
-1
0
2

func IndexUint16 added in v0.0.4

func IndexUint16(slice []uint16, target uint16) int
Example
slice := []uint16{1, 2, 3}
fmt.Println(IndexUint16(nil, 3))
fmt.Println(IndexUint16(slice, 0))
fmt.Println(IndexUint16(slice, 1))
fmt.Println(IndexUint16(slice, 3))
Output:

-1
-1
0
2

func IndexUint32 added in v0.0.4

func IndexUint32(slice []uint32, target uint32) int
Example
slice := []uint32{1, 2, 3}
fmt.Println(IndexUint32(nil, 3))
fmt.Println(IndexUint32(slice, 0))
fmt.Println(IndexUint32(slice, 1))
fmt.Println(IndexUint32(slice, 3))
Output:

-1
-1
0
2

func IndexUint64 added in v0.0.4

func IndexUint64(slice []uint64, target uint64) int
Example
slice := []uint64{1, 2, 3}
fmt.Println(IndexUint64(nil, 3))
fmt.Println(IndexUint64(slice, 0))
fmt.Println(IndexUint64(slice, 1))
fmt.Println(IndexUint64(slice, 3))
Output:

-1
-1
0
2

func IndexUint8 added in v0.0.4

func IndexUint8(slice []uint8, target uint8) int
Example
slice := []uint8{1, 2, 3}
fmt.Println(IndexUint8(nil, 3))
fmt.Println(IndexUint8(slice, 0))
fmt.Println(IndexUint8(slice, 1))
fmt.Println(IndexUint8(slice, 3))
Output:

-1
-1
0
2

func IndexValue

func IndexValue(slice reflect.Value, target interface{}) int
Example
fmt.Println(IndexValue(reflect.ValueOf([]int(nil)), 3))
var slice = reflect.ValueOf([]T{{3, "c"}, {}, {2, "b"}, {9, "f"}})
fmt.Println(IndexValue(slice, 3))
fmt.Println(IndexValue(slice, T{2, "c"}))
fmt.Println(IndexValue(slice, T{2, "b"}))
Output:

-1
-1
-1
2

func InsertBool added in v0.1.0

func InsertBool(slice []bool, i int, value bool) []bool

InsertBool insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertBool(nil, 0, true))
fmt.Println(InsertBool([]bool{}, 0, true))
fmt.Println(InsertBool([]bool{false, true}, 0, true))
fmt.Println(InsertBool([]bool{false, true}, 1, true))
fmt.Println(InsertBool([]bool{false, true}, 2, true))
Output:

[true]
[true]
[true false true]
[false true true]
[false true true]

func InsertGeneric added in v0.0.5

func InsertGeneric(slice interface{}, i int, value interface{}) interface{}

Insert insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertGeneric([]string(nil), 0, "a"))
fmt.Println(InsertGeneric([]string{}, 0, "a"))
fmt.Println(InsertGeneric([]string{"b", "c"}, 0, "a"))
fmt.Println(InsertGeneric([]string{"b", "c"}, 1, "a"))
fmt.Println(InsertGeneric([]string{"b", "c"}, 2, "a"))
Output:

[a]
[a]
[a b c]
[b a c]
[b c a]

func InsertInt added in v0.0.4

func InsertInt(slice []int, i int, value int) []int

InsertInt insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertInt(nil, 0, 3))
fmt.Println(InsertInt([]int{}, 0, 3))
fmt.Println(InsertInt([]int{2, 3}, 0, 1))
fmt.Println(InsertInt([]int{2, 3}, 1, 1))
fmt.Println(InsertInt([]int{2, 3}, 2, 1))
Output:

[3]
[3]
[1 2 3]
[2 1 3]
[2 3 1]

func InsertInt16 added in v0.0.4

func InsertInt16(slice []int16, i int, value int16) []int16

InsertInt16 insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertInt16(nil, 0, 3))
fmt.Println(InsertInt16([]int16{}, 0, 3))
fmt.Println(InsertInt16([]int16{2, 3}, 0, 1))
fmt.Println(InsertInt16([]int16{2, 3}, 1, 1))
fmt.Println(InsertInt16([]int16{2, 3}, 2, 1))
Output:

[3]
[3]
[1 2 3]
[2 1 3]
[2 3 1]

func InsertInt32 added in v0.0.4

func InsertInt32(slice []int32, i int, value int32) []int32

InsertInt32 insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertInt32(nil, 0, 3))
fmt.Println(InsertInt32([]int32{}, 0, 3))
fmt.Println(InsertInt32([]int32{2, 3}, 0, 1))
fmt.Println(InsertInt32([]int32{2, 3}, 1, 1))
fmt.Println(InsertInt32([]int32{2, 3}, 2, 1))
Output:

[3]
[3]
[1 2 3]
[2 1 3]
[2 3 1]

func InsertInt64

func InsertInt64(slice []int64, i int, value int64) []int64

InsertInt64 insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertInt64(nil, 0, 3))
fmt.Println(InsertInt64([]int64{}, 0, 3))
fmt.Println(InsertInt64([]int64{2, 3}, 0, 1))
fmt.Println(InsertInt64([]int64{2, 3}, 1, 1))
fmt.Println(InsertInt64([]int64{2, 3}, 2, 1))
Output:

[3]
[3]
[1 2 3]
[2 1 3]
[2 3 1]

func InsertInt8 added in v0.0.4

func InsertInt8(slice []int8, i int, value int8) []int8

InsertInt8 insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertInt8(nil, 0, 3))
fmt.Println(InsertInt8([]int8{}, 0, 3))
fmt.Println(InsertInt8([]int8{2, 3}, 0, 1))
fmt.Println(InsertInt8([]int8{2, 3}, 1, 1))
fmt.Println(InsertInt8([]int8{2, 3}, 2, 1))
Output:

[3]
[3]
[1 2 3]
[2 1 3]
[2 3 1]

func InsertInterface added in v0.0.4

func InsertInterface(slice []interface{}, i int, value interface{}) []interface{}

InsertInterface insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertInterface(nil, 0, "a"))
fmt.Println(InsertInterface([]interface{}{}, 0, "a"))
fmt.Println(InsertInterface([]interface{}{"b", 1}, 0, "a"))
fmt.Println(InsertInterface([]interface{}{"b", 1}, 1, "a"))
fmt.Println(InsertInterface([]interface{}{"b", 1}, 2, "a"))
Output:

[a]
[a]
[a b 1]
[b a 1]
[b 1 a]

func InsertString

func InsertString(slice []string, i int, value string) []string

InsertString insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertString(nil, 0, "a"))
fmt.Println(InsertString([]string{}, 0, "a"))
fmt.Println(InsertString([]string{"b", "c"}, 0, "a"))
fmt.Println(InsertString([]string{"b", "c"}, 1, "a"))
fmt.Println(InsertString([]string{"b", "c"}, 2, "a"))
Output:

[a]
[a]
[a b c]
[b a c]
[b c a]

func InsertUint added in v0.0.4

func InsertUint(slice []uint, i int, value uint) []uint

InsertUint insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertUint(nil, 0, 3))
fmt.Println(InsertUint([]uint{}, 0, 3))
fmt.Println(InsertUint([]uint{2, 3}, 0, 1))
fmt.Println(InsertUint([]uint{2, 3}, 1, 1))
fmt.Println(InsertUint([]uint{2, 3}, 2, 1))
Output:

[3]
[3]
[1 2 3]
[2 1 3]
[2 3 1]

func InsertUint16 added in v0.0.4

func InsertUint16(slice []uint16, i int, value uint16) []uint16

InsertUint16 insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertUint16(nil, 0, 3))
fmt.Println(InsertUint16([]uint16{}, 0, 3))
fmt.Println(InsertUint16([]uint16{2, 3}, 0, 1))
fmt.Println(InsertUint16([]uint16{2, 3}, 1, 1))
fmt.Println(InsertUint16([]uint16{2, 3}, 2, 1))
Output:

[3]
[3]
[1 2 3]
[2 1 3]
[2 3 1]

func InsertUint32 added in v0.0.4

func InsertUint32(slice []uint32, i int, value uint32) []uint32

InsertUint32 insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertUint32(nil, 0, 3))
fmt.Println(InsertUint32([]uint32{}, 0, 3))
fmt.Println(InsertUint32([]uint32{2, 3}, 0, 1))
fmt.Println(InsertUint32([]uint32{2, 3}, 1, 1))
fmt.Println(InsertUint32([]uint32{2, 3}, 2, 1))
Output:

[3]
[3]
[1 2 3]
[2 1 3]
[2 3 1]

func InsertUint64 added in v0.0.4

func InsertUint64(slice []uint64, i int, value uint64) []uint64

InsertUint64 insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertUint64(nil, 0, 3))
fmt.Println(InsertUint64([]uint64{}, 0, 3))
fmt.Println(InsertUint64([]uint64{2, 3}, 0, 1))
fmt.Println(InsertUint64([]uint64{2, 3}, 1, 1))
fmt.Println(InsertUint64([]uint64{2, 3}, 2, 1))
Output:

[3]
[3]
[1 2 3]
[2 1 3]
[2 3 1]

func InsertUint8 added in v0.0.4

func InsertUint8(slice []uint8, i int, value uint8) []uint8

InsertUint8 insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertUint8(nil, 0, 3))
fmt.Println(InsertUint8([]uint8{}, 0, 3))
fmt.Println(InsertUint8([]uint8{2, 3}, 0, 1))
fmt.Println(InsertUint8([]uint8{2, 3}, 1, 1))
fmt.Println(InsertUint8([]uint8{2, 3}, 2, 1))
Output:

[3]
[3]
[1 2 3]
[2 1 3]
[2 3 1]

func InsertValue

func InsertValue(slice reflect.Value, i int, value reflect.Value) reflect.Value

InsertValue insert value at index i, it panics if i > len(slice). The input slice will be modified.

Example
fmt.Println(InsertValue(reflect.ValueOf([]string(nil)), 0, reflect.ValueOf("a")))
fmt.Println(InsertValue(reflect.ValueOf([]string{}), 0, reflect.ValueOf("a")))
fmt.Println(InsertValue(reflect.ValueOf([]string{"b", "c"}), 0, reflect.ValueOf("a")))
fmt.Println(InsertValue(reflect.ValueOf([]string{"b", "c"}), 1, reflect.ValueOf("a")))
fmt.Println(InsertValue(reflect.ValueOf([]string{"b", "c"}), 2, reflect.ValueOf("a")))
Output:

[a]
[a]
[a b c]
[b a c]
[b c a]

func IntersectBool added in v0.1.0

func IntersectBool(left, right []bool) []bool

IntersectBool returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = []bool{true, false, true}
fmt.Println(IntersectBool(left, []bool{false, true}))
fmt.Println(IntersectBool(left, []bool{true, true}))
fmt.Println(IntersectBool(left, nil))
Output:

[true false true]
[true true]
[]

func IntersectGeneric added in v0.0.5

func IntersectGeneric(left, right interface{}) interface{}

IntersectGeneric returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = []T{{3, "c"}, {}, {2, "b"}, {9, "f"}, {2, "b"}}
fmt.Println(IntersectGeneric(left, nil))
fmt.Printf("%#v\n", IntersectGeneric(left, []int64{}))
fmt.Println(IntersectGeneric(left, []T{{}, {2, "b"}}))
Output:

<nil>
[]slice.T(nil)
[{0 } {2 b} {2 b}]

func IntersectInt added in v0.0.4

func IntersectInt(left, right []int) []int

IntersectInt returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = []int{1, 2, 3, 4, 2}
fmt.Println(IntersectInt(left, []int{2, 1, 5}))
fmt.Println(IntersectInt(left, []int{0, 5}))
fmt.Println(IntersectInt(left, nil))
Output:

[1 2 2]
[]
[]

func IntersectInt16 added in v0.0.4

func IntersectInt16(left, right []int16) []int16

IntersectInt16 returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = []int16{1, 2, 3, 4, 2}
fmt.Println(IntersectInt16(left, []int16{2, 1, 5}))
fmt.Println(IntersectInt16(left, []int16{0, 5}))
fmt.Println(IntersectInt16(left, nil))
Output:

[1 2 2]
[]
[]

func IntersectInt32 added in v0.0.4

func IntersectInt32(left, right []int32) []int32

IntersectInt32 returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = []int32{1, 2, 3, 4, 2}
fmt.Println(IntersectInt32(left, []int32{2, 1, 5}))
fmt.Println(IntersectInt32(left, []int32{0, 5}))
fmt.Println(IntersectInt32(left, nil))
Output:

[1 2 2]
[]
[]

func IntersectInt64

func IntersectInt64(left, right []int64) []int64

IntersectInt64 returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = []int64{1, 2, 3, 4, 2}
fmt.Println(IntersectInt64(left, []int64{2, 1, 5}))
fmt.Println(IntersectInt64(left, []int64{0, 5}))
fmt.Println(IntersectInt64(left, nil))
Output:

[1 2 2]
[]
[]

func IntersectInt8 added in v0.0.4

func IntersectInt8(left, right []int8) []int8

IntersectInt8 returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = []int8{1, 2, 3, 4, 2}
fmt.Println(IntersectInt8(left, []int8{2, 1, 5}))
fmt.Println(IntersectInt8(left, []int8{0, 5}))
fmt.Println(IntersectInt8(left, nil))
Output:

[1 2 2]
[]
[]

func IntersectInterface added in v0.0.4

func IntersectInterface(left, right []interface{}) []interface{}

IntersectInterface returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = []interface{}{1, 1, `2`, 3, `4`}
fmt.Println(IntersectInterface(left, []interface{}{`2`, 1, `3`}))
fmt.Println(IntersectInterface(left, []interface{}{0, 5}))
fmt.Println(IntersectInterface(left, nil))
Output:

[1 1 2]
[]
[]

func IntersectString added in v0.0.4

func IntersectString(left, right []string) []string

IntersectString returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = []string{"a", "b", "c", "d", "b"}
fmt.Println(IntersectString(left, []string{"b", "a", "e"}))
fmt.Println(IntersectString(left, []string{"x", "e"}))
fmt.Println(IntersectString(left, nil))
Output:

[a b b]
[]
[]

func IntersectUint added in v0.0.4

func IntersectUint(left, right []uint) []uint

IntersectUint returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = []uint{1, 2, 3, 4, 2}
fmt.Println(IntersectUint(left, []uint{2, 1, 5}))
fmt.Println(IntersectUint(left, []uint{0, 5}))
fmt.Println(IntersectUint(left, nil))
Output:

[1 2 2]
[]
[]

func IntersectUint16 added in v0.0.4

func IntersectUint16(left, right []uint16) []uint16

IntersectUint16 returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = []uint16{1, 2, 3, 4, 2}
fmt.Println(IntersectUint16(left, []uint16{2, 1, 5}))
fmt.Println(IntersectUint16(left, []uint16{0, 5}))
fmt.Println(IntersectUint16(left, nil))
Output:

[1 2 2]
[]
[]

func IntersectUint32 added in v0.0.4

func IntersectUint32(left, right []uint32) []uint32

IntersectUint32 returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = []uint32{1, 2, 3, 4, 2}
fmt.Println(IntersectUint32(left, []uint32{2, 1, 5}))
fmt.Println(IntersectUint32(left, []uint32{0, 5}))
fmt.Println(IntersectUint32(left, nil))
Output:

[1 2 2]
[]
[]

func IntersectUint64 added in v0.0.4

func IntersectUint64(left, right []uint64) []uint64

IntersectUint64 returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = []uint64{1, 2, 3, 4, 2}
fmt.Println(IntersectUint64(left, []uint64{2, 1, 5}))
fmt.Println(IntersectUint64(left, []uint64{0, 5}))
fmt.Println(IntersectUint64(left, []uint64{}))
Output:

[1 2 2]
[]
[]

func IntersectUint8 added in v0.0.4

func IntersectUint8(left, right []uint8) []uint8

IntersectUint8 returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = []uint8{1, 2, 3, 4, 2}
fmt.Println(IntersectUint8(left, []uint8{2, 1, 5}))
fmt.Println(IntersectUint8(left, []uint8{0, 5}))
fmt.Println(IntersectUint8(left, nil))
Output:

[1 2 2]
[]
[]

func IntersectValue added in v0.0.4

func IntersectValue(left, right reflect.Value) reflect.Value

IntersectValue returns intersection of left and right, in the left order. The duplicate members in left are kept.

Example
var left = reflect.ValueOf([]T{{3, "c"}, {}, {2, "b"}, {9, "f"}, {2, "b"}})
fmt.Println(IntersectValue(left, reflect.ValueOf(nil)))
fmt.Printf("%#v\n", IntersectValue(left, reflect.ValueOf([]int64{})))
fmt.Println(IntersectValue(left, reflect.ValueOf([]T{{}, {2, "b"}})))
Output:

[]
[]slice.T(nil)
[{0 } {2 b} {2 b}]

func LastIndex

func LastIndex(length int, fun func(int) bool) int
Example
fmt.Println(LastIndex(0, func(i int) bool { return true }))
var slice = []T{{3, "c"}, {}, {2, "b"}, {}, {9, "f"}}
var length = len(slice)
fmt.Println(LastIndex(length, func(i int) bool { return slice[i] == T{} }))
fmt.Println(LastIndex(length, func(i int) bool { return slice[i] == T{2, "c"} }))
Output:

-1
3
-1

func LastIndexBool added in v0.1.0

func LastIndexBool(slice []bool, target bool) int
Example
fmt.Println(LastIndexBool([]bool{}, false))
slice := []bool{true, false, false, true}
fmt.Println(LastIndexBool(slice, true))
fmt.Println(LastIndexBool(slice, false))
Output:

-1
3
2

func LastIndexGeneric added in v0.0.5

func LastIndexGeneric(slice interface{}, target interface{}) int
Example
fmt.Println(LastIndexGeneric(nil, T{}))
var slice = []T{{3, "c"}, {}, {2, "b"}, {}, {9, "f"}}
fmt.Println(LastIndexGeneric(slice, T{}))
fmt.Println(LastIndexGeneric(slice, T{2, "c"}))
Output:

-1
3
-1

func LastIndexInt

func LastIndexInt(slice []int, target int) int
Example
slice := []int{1, 2, 3, 1, 2}
fmt.Println(LastIndexInt(slice, 1))
fmt.Println(LastIndexInt(slice, 4))
Output:

3
-1

func LastIndexInt16 added in v0.0.4

func LastIndexInt16(slice []int16, target int16) int
Example
slice := []int16{1, 2, 3, 1, 2}
fmt.Println(LastIndexInt16(slice, 1))
fmt.Println(LastIndexInt16(slice, 4))
Output:

3
-1

func LastIndexInt32 added in v0.0.4

func LastIndexInt32(slice []int32, target int32) int
Example
slice := []int32{1, 2, 3, 1, 2}
fmt.Println(LastIndexInt32(slice, 1))
fmt.Println(LastIndexInt32(slice, 4))
Output:

3
-1

func LastIndexInt64

func LastIndexInt64(slice []int64, target int64) int
Example
var slice = []int64{1, 2, 3, 1, 2}
fmt.Println(LastIndexInt64(slice, 1))
fmt.Println(LastIndexInt64(slice, 4))
Output:

3
-1

func LastIndexInt8 added in v0.0.4

func LastIndexInt8(slice []int8, target int8) int
Example
slice := []int8{1, 2, 3, 1, 2}
fmt.Println(LastIndexInt8(slice, 1))
fmt.Println(LastIndexInt8(slice, 4))
Output:

3
-1

func LastIndexInterface added in v0.0.4

func LastIndexInterface(slice []interface{}, target interface{}) int
Example
slice := []interface{}{`1`, `2`, `3`, `1`}
fmt.Println(LastIndexInterface(slice, `1`))
fmt.Println(LastIndexInterface(slice, 1))
Output:

3
-1

func LastIndexString

func LastIndexString(slice []string, target string) int
Example
slice := []string{`1`, `2`, `3`, `1`}
fmt.Println(LastIndexString(slice, `1`))
fmt.Println(LastIndexString(slice, `4`))
Output:

3
-1

func LastIndexUint added in v0.0.4

func LastIndexUint(slice []uint, target uint) int
Example
slice := []uint{1, 2, 3, 1, 2}
fmt.Println(LastIndexUint(slice, 1))
fmt.Println(LastIndexUint(slice, 4))
Output:

3
-1

func LastIndexUint16 added in v0.0.4

func LastIndexUint16(slice []uint16, target uint16) int
Example
slice := []uint16{1, 2, 3, 1, 2}
fmt.Println(LastIndexUint16(slice, 1))
fmt.Println(LastIndexUint16(slice, 4))
Output:

3
-1

func LastIndexUint32 added in v0.0.4

func LastIndexUint32(slice []uint32, target uint32) int
Example
slice := []uint32{1, 2, 3, 1, 2}
fmt.Println(LastIndexUint32(slice, 1))
fmt.Println(LastIndexUint32(slice, 4))
Output:

3
-1

func LastIndexUint64 added in v0.0.4

func LastIndexUint64(slice []uint64, target uint64) int
Example
var slice = []uint64{1, 2, 3, 1, 2}
fmt.Println(LastIndexUint64(slice, 1))
fmt.Println(LastIndexUint64(slice, 4))
Output:

3
-1

func LastIndexUint8 added in v0.0.4

func LastIndexUint8(slice []uint8, target uint8) int
Example
slice := []uint8{1, 2, 3, 1, 2}
fmt.Println(LastIndexUint8(slice, 1))
fmt.Println(LastIndexUint8(slice, 4))
Output:

3
-1

func LastIndexValue

func LastIndexValue(slice reflect.Value, target interface{}) int
Example
fmt.Println(LastIndexValue(reflect.ValueOf([]T{}), T{}))
var slice = reflect.ValueOf([]T{{3, "c"}, {}, {2, "b"}, {}, {9, "f"}})
fmt.Println(LastIndexValue(slice, T{}))
fmt.Println(LastIndexValue(slice, T{2, "c"}))
Output:

-1
3
-1

func MoveBackward

func MoveBackward(slice interface{}, i, n int) interface{}

MoveBackward move elements starting at i backward n steps. It panics if i > len(slice) The input slice will be modified.

Example
fmt.Println(MoveBackward(make([]int, 0, 4), 0, 3))
fmt.Println(MoveBackward([]int{0, 4, 5}, 0, 3))
fmt.Println(MoveBackward([]int{0, 4, 5}, 1, 3))
fmt.Println(MoveBackward([]int{0, 4, 5}, 2, 3))
fmt.Println(MoveBackward([]int{0, 4, 5}, 3, 3))
Output:

[0 0 0]
[0 4 5 0 4 5]
[0 4 5 0 4 5]
[0 4 5 0 0 5]
[0 4 5 0 0 0]

func Remove

func Remove(slice interface{}, fun func(int) bool) interface{}
Example
fmt.Println(Remove([]int{1, 2, 2, 3}, func(i int) bool { return i < 2 }))
Output:

[2 3]

func RemoveBool added in v0.1.0

func RemoveBool(slice []bool, targets ...bool) []bool
Example
fmt.Println(RemoveBool([]bool{}))
fmt.Println(RemoveBool([]bool{true, false, false, true}))
fmt.Println(RemoveBool([]bool{true, false, false, true}, false))
fmt.Println(RemoveBool([]bool{true, false, false, true}, true, false))
Output:

[]
[true false false true]
[true true]
[]

func RemoveGeneric added in v0.1.0

func RemoveGeneric(slice interface{}, targets ...interface{}) interface{}
Example
fmt.Println(RemoveGeneric([]int{1, 2, 2, 3}))
fmt.Println(RemoveGeneric([]int{1, 2, 2, 3}, 2))
Output:

[1 2 2 3]
[1 3]

func RemoveInt added in v0.1.0

func RemoveInt(slice []int, targets ...int) []int
Example
fmt.Println(RemoveInt([]int{1, 2, 2, 3}))
fmt.Println(RemoveInt([]int{1, 2, 2, 3}, 2))
fmt.Println(RemoveInt([]int{1, 2, 2, 3}, 1, 2))
Output:

[1 2 2 3]
[1 3]
[3]

func RemoveInt16 added in v0.1.0

func RemoveInt16(slice []int16, targets ...int16) []int16
Example
fmt.Println(RemoveInt16([]int16{1, 2, 2, 3}))
fmt.Println(RemoveInt16([]int16{1, 2, 2, 3}, 2))
fmt.Println(RemoveInt16([]int16{1, 2, 2, 3}, 1, 2))
Output:

[1 2 2 3]
[1 3]
[3]

func RemoveInt32 added in v0.1.0

func RemoveInt32(slice []int32, targets ...int32) []int32
Example
fmt.Println(RemoveInt32([]int32{1, 2, 2, 3}))
fmt.Println(RemoveInt32([]int32{1, 2, 2, 3}, 2))
fmt.Println(RemoveInt32([]int32{1, 2, 2, 3}, 1, 2))
Output:

[1 2 2 3]
[1 3]
[3]

func RemoveInt64

func RemoveInt64(slice []int64, targets ...int64) []int64
Example
fmt.Println(RemoveInt64([]int64{1, 2, 2, 3}))
fmt.Println(RemoveInt64([]int64{1, 2, 2, 3}, 2))
fmt.Println(RemoveInt64([]int64{1, 2, 2, 3}, 1, 2))
Output:

[1 2 2 3]
[1 3]
[3]

func RemoveInt8 added in v0.1.0

func RemoveInt8(slice []int8, targets ...int8) []int8
Example
fmt.Println(RemoveInt8([]int8{1, 2, 2, 3}))
fmt.Println(RemoveInt8([]int8{1, 2, 2, 3}, 2))
fmt.Println(RemoveInt8([]int8{1, 2, 2, 3}, 1, 2))
Output:

[1 2 2 3]
[1 3]
[3]

func RemoveInterface added in v0.1.0

func RemoveInterface(slice []interface{}, targets ...interface{}) []interface{}
Example
fmt.Println(RemoveInterface([]interface{}{1, 2, 2, "c"}))
fmt.Println(RemoveInterface([]interface{}{1, 2, 2, "c"}, 2))
fmt.Println(RemoveInterface([]interface{}{1, 2, 2, "c"}, 1, 2))
Output:

[1 2 2 c]
[1 c]
[c]

func RemoveString added in v0.1.0

func RemoveString(slice []string, targets ...string) []string
Example
fmt.Println(RemoveString([]string{"a", "b", "b", "c"}))
fmt.Println(RemoveString([]string{"a", "b", "b", "c"}, "b"))
fmt.Println(RemoveString([]string{"a", "b", "b", "c"}, "a", "b"))
Output:

[a b b c]
[a c]
[c]

func RemoveUint added in v0.1.0

func RemoveUint(slice []uint, targets ...uint) []uint
Example
fmt.Println(RemoveUint([]uint{1, 2, 2, 3}))
fmt.Println(RemoveUint([]uint{1, 2, 2, 3}, 2))
fmt.Println(RemoveUint([]uint{1, 2, 2, 3}, 1, 2))
Output:

[1 2 2 3]
[1 3]
[3]

func RemoveUint16 added in v0.1.0

func RemoveUint16(slice []uint16, targets ...uint16) []uint16
Example
fmt.Println(RemoveUint16([]uint16{1, 2, 2, 3}))
fmt.Println(RemoveUint16([]uint16{1, 2, 2, 3}, 2))
fmt.Println(RemoveUint16([]uint16{1, 2, 2, 3}, 1, 2))
Output:

[1 2 2 3]
[1 3]
[3]

func RemoveUint32 added in v0.1.0

func RemoveUint32(slice []uint32, targets ...uint32) []uint32
Example
fmt.Println(RemoveUint32([]uint32{1, 2, 2, 3}))
fmt.Println(RemoveUint32([]uint32{1, 2, 2, 3}, 2))
fmt.Println(RemoveUint32([]uint32{1, 2, 2, 3}, 1, 2))
Output:

[1 2 2 3]
[1 3]
[3]

func RemoveUint64 added in v0.1.0

func RemoveUint64(slice []uint64, targets ...uint64) []uint64
Example
fmt.Println(RemoveUint64([]uint64{1, 2, 2, 3}))
fmt.Println(RemoveUint64([]uint64{1, 2, 2, 3}, 2))
fmt.Println(RemoveUint64([]uint64{1, 2, 2, 3}, 1, 2))
Output:

[1 2 2 3]
[1 3]
[3]

func RemoveUint8 added in v0.1.0

func RemoveUint8(slice []uint8, targets ...uint8) []uint8
Example
fmt.Println(RemoveUint8([]uint8{1, 2, 2, 3}))
fmt.Println(RemoveUint8([]uint8{1, 2, 2, 3}, 2))
fmt.Println(RemoveUint8([]uint8{1, 2, 2, 3}, 1, 2))
Output:

[1 2 2 3]
[1 3]
[3]

func RemoveValue added in v0.1.0

func RemoveValue(slice reflect.Value, targets ...interface{}) interface{}
Example
fmt.Println(RemoveValue(reflect.ValueOf([]int{1, 2, 2, 3}), 1, 3))
Output:

[2 2]

func SplitBool added in v0.1.0

func SplitBool(slice []bool, sep bool) (result [][]bool)
Example
fmt.Println(SplitBool([]bool{}, false))
fmt.Println(SplitBool([]bool{false}, false))
fmt.Println(SplitBool([]bool{true}, false))
fmt.Println(SplitBool([]bool{true, true}, false))
fmt.Println(SplitBool([]bool{true, true, false}, false))
fmt.Println(SplitBool([]bool{true, true, false, true}, false))
fmt.Println(SplitBool([]bool{true, true, false, true, true}, false))
fmt.Println(SplitBool([]bool{true, true, false, true, true, false}, false))
Output:

[]
[[] []]
[[true]]
[[true true]]
[[true true] []]
[[true true] [true]]
[[true true] [true true]]
[[true true] [true true] []]

func SplitGeneric added in v0.0.5

func SplitGeneric(slice, sep interface{}) interface{}
Example
fmt.Println(SplitGeneric([]T{}, T{}))
fmt.Println(SplitGeneric([]T{T{}}, T{}))
fmt.Println(SplitGeneric([]T{T{1, "a"}}, T{}))
fmt.Println(SplitGeneric([]T{T{1, "a"}, T{2, "b"}}, T{}))
fmt.Println(SplitGeneric([]T{T{1, "a"}, T{2, "b"}, T{}}, T{}))
fmt.Println(SplitGeneric([]T{T{1, "a"}, T{2, "b"}, T{}, T{3, "c"}}, T{}))
fmt.Println(SplitGeneric([]T{T{1, "a"}, T{2, "b"}, T{}, T{3, "c"}, T{4, "d"}}, T{}))
fmt.Println(SplitGeneric([]T{T{1, "a"}, T{2, "b"}, T{}, T{3, "c"}, T{4, "d"}, T{}}, T{}))
Output:

[]
[[] []]
[[{1 a}]]
[[{1 a} {2 b}]]
[[{1 a} {2 b}] []]
[[{1 a} {2 b}] [{3 c}]]
[[{1 a} {2 b}] [{3 c} {4 d}]]
[[{1 a} {2 b}] [{3 c} {4 d}] []]

func SplitInt added in v0.0.4

func SplitInt(slice []int, sep int) (result [][]int)
Example
fmt.Println(SplitInt([]int{}, 0))
fmt.Println(SplitInt([]int{0}, 0))
fmt.Println(SplitInt([]int{1}, 0))
fmt.Println(SplitInt([]int{1, 2}, 0))
fmt.Println(SplitInt([]int{1, 2, 0}, 0))
fmt.Println(SplitInt([]int{1, 2, 0, 3}, 0))
fmt.Println(SplitInt([]int{1, 2, 0, 3, 4}, 0))
fmt.Println(SplitInt([]int{1, 2, 0, 3, 4, 0}, 0))
Output:

[]
[[] []]
[[1]]
[[1 2]]
[[1 2] []]
[[1 2] [3]]
[[1 2] [3 4]]
[[1 2] [3 4] []]

func SplitInt16 added in v0.0.4

func SplitInt16(slice []int16, sep int16) (result [][]int16)
Example
fmt.Println(SplitInt16([]int16{}, 0))
fmt.Println(SplitInt16([]int16{0}, 0))
fmt.Println(SplitInt16([]int16{1}, 0))
fmt.Println(SplitInt16([]int16{1, 2}, 0))
fmt.Println(SplitInt16([]int16{1, 2, 0}, 0))
fmt.Println(SplitInt16([]int16{1, 2, 0, 3}, 0))
fmt.Println(SplitInt16([]int16{1, 2, 0, 3, 4}, 0))
fmt.Println(SplitInt16([]int16{1, 2, 0, 3, 4, 0}, 0))
Output:

[]
[[] []]
[[1]]
[[1 2]]
[[1 2] []]
[[1 2] [3]]
[[1 2] [3 4]]
[[1 2] [3 4] []]

func SplitInt32 added in v0.0.4

func SplitInt32(slice []int32, sep int32) (result [][]int32)
Example
fmt.Println(SplitInt32([]int32{}, 0))
fmt.Println(SplitInt32([]int32{0}, 0))
fmt.Println(SplitInt32([]int32{1}, 0))
fmt.Println(SplitInt32([]int32{1, 2}, 0))
fmt.Println(SplitInt32([]int32{1, 2, 0}, 0))
fmt.Println(SplitInt32([]int32{1, 2, 0, 3}, 0))
fmt.Println(SplitInt32([]int32{1, 2, 0, 3, 4}, 0))
fmt.Println(SplitInt32([]int32{1, 2, 0, 3, 4, 0}, 0))
Output:

[]
[[] []]
[[1]]
[[1 2]]
[[1 2] []]
[[1 2] [3]]
[[1 2] [3 4]]
[[1 2] [3 4] []]

func SplitInt64 added in v0.0.4

func SplitInt64(slice []int64, sep int64) (result [][]int64)
Example
fmt.Println(SplitInt64([]int64{}, 0))
fmt.Println(SplitInt64([]int64{0}, 0))
fmt.Println(SplitInt64([]int64{1}, 0))
fmt.Println(SplitInt64([]int64{1, 2}, 0))
fmt.Println(SplitInt64([]int64{1, 2, 0}, 0))
fmt.Println(SplitInt64([]int64{1, 2, 0, 3}, 0))
fmt.Println(SplitInt64([]int64{1, 2, 0, 3, 4}, 0))
fmt.Println(SplitInt64([]int64{1, 2, 0, 3, 4, 0}, 0))
Output:

[]
[[] []]
[[1]]
[[1 2]]
[[1 2] []]
[[1 2] [3]]
[[1 2] [3 4]]
[[1 2] [3 4] []]

func SplitInt8 added in v0.0.4

func SplitInt8(slice []int8, sep int8) (result [][]int8)
Example
fmt.Println(SplitInt8([]int8{}, 0))
fmt.Println(SplitInt8([]int8{0}, 0))
fmt.Println(SplitInt8([]int8{1}, 0))
fmt.Println(SplitInt8([]int8{1, 2}, 0))
fmt.Println(SplitInt8([]int8{1, 2, 0}, 0))
fmt.Println(SplitInt8([]int8{1, 2, 0, 3}, 0))
fmt.Println(SplitInt8([]int8{1, 2, 0, 3, 4}, 0))
fmt.Println(SplitInt8([]int8{1, 2, 0, 3, 4, 0}, 0))
Output:

[]
[[] []]
[[1]]
[[1 2]]
[[1 2] []]
[[1 2] [3]]
[[1 2] [3 4]]
[[1 2] [3 4] []]

func SplitInterface added in v0.0.4

func SplitInterface(slice []interface{}, sep interface{}) (result [][]interface{})
Example
fmt.Println(SplitInterface([]interface{}{}, "--"))
fmt.Println(SplitInterface([]interface{}{"--"}, "--"))
fmt.Println(SplitInterface([]interface{}{"a"}, "--"))
fmt.Println(SplitInterface([]interface{}{"a", 1}, "--"))
fmt.Println(SplitInterface([]interface{}{"a", 1, "--"}, "--"))
fmt.Println(SplitInterface([]interface{}{"a", 1, "--", "c"}, "--"))
fmt.Println(SplitInterface([]interface{}{"a", 1, "--", "c", 3}, "--"))
fmt.Println(SplitInterface([]interface{}{"a", 1, "--", "c", 3, "--"}, "--"))
Output:

[]
[[] []]
[[a]]
[[a 1]]
[[a 1] []]
[[a 1] [c]]
[[a 1] [c 3]]
[[a 1] [c 3] []]

func SplitString added in v0.0.4

func SplitString(slice []string, sep string) (result [][]string)
Example
fmt.Println(SplitString([]string{}, "--"))
fmt.Println(SplitString([]string{"--"}, "--"))
fmt.Println(SplitString([]string{"a"}, "--"))
fmt.Println(SplitString([]string{"a", "b"}, "--"))
fmt.Println(SplitString([]string{"a", "b", "--"}, "--"))
fmt.Println(SplitString([]string{"a", "b", "--", "c"}, "--"))
fmt.Println(SplitString([]string{"a", "b", "--", "c", "d"}, "--"))
fmt.Println(SplitString([]string{"a", "b", "--", "c", "d", "--"}, "--"))
Output:

[]
[[] []]
[[a]]
[[a b]]
[[a b] []]
[[a b] [c]]
[[a b] [c d]]
[[a b] [c d] []]

func SplitUint added in v0.0.4

func SplitUint(slice []uint, sep uint) (result [][]uint)
Example
fmt.Println(SplitUint([]uint{}, 0))
fmt.Println(SplitUint([]uint{0}, 0))
fmt.Println(SplitUint([]uint{1}, 0))
fmt.Println(SplitUint([]uint{1, 2}, 0))
fmt.Println(SplitUint([]uint{1, 2, 0}, 0))
fmt.Println(SplitUint([]uint{1, 2, 0, 3}, 0))
fmt.Println(SplitUint([]uint{1, 2, 0, 3, 4}, 0))
fmt.Println(SplitUint([]uint{1, 2, 0, 3, 4, 0}, 0))
Output:

[]
[[] []]
[[1]]
[[1 2]]
[[1 2] []]
[[1 2] [3]]
[[1 2] [3 4]]
[[1 2] [3 4] []]

func SplitUint16 added in v0.0.4

func SplitUint16(slice []uint16, sep uint16) (result [][]uint16)
Example
fmt.Println(SplitUint16([]uint16{}, 0))
fmt.Println(SplitUint16([]uint16{0}, 0))
fmt.Println(SplitUint16([]uint16{1}, 0))
fmt.Println(SplitUint16([]uint16{1, 2}, 0))
fmt.Println(SplitUint16([]uint16{1, 2, 0}, 0))
fmt.Println(SplitUint16([]uint16{1, 2, 0, 3}, 0))
fmt.Println(SplitUint16([]uint16{1, 2, 0, 3, 4}, 0))
fmt.Println(SplitUint16([]uint16{1, 2, 0, 3, 4, 0}, 0))
Output:

[]
[[] []]
[[1]]
[[1 2]]
[[1 2] []]
[[1 2] [3]]
[[1 2] [3 4]]
[[1 2] [3 4] []]

func SplitUint32 added in v0.0.4

func SplitUint32(slice []uint32, sep uint32) (result [][]uint32)
Example
fmt.Println(SplitUint32([]uint32{}, 0))
fmt.Println(SplitUint32([]uint32{0}, 0))
fmt.Println(SplitUint32([]uint32{1}, 0))
fmt.Println(SplitUint32([]uint32{1, 2}, 0))
fmt.Println(SplitUint32([]uint32{1, 2, 0}, 0))
fmt.Println(SplitUint32([]uint32{1, 2, 0, 3}, 0))
fmt.Println(SplitUint32([]uint32{1, 2, 0, 3, 4}, 0))
fmt.Println(SplitUint32([]uint32{1, 2, 0, 3, 4, 0}, 0))
Output:

[]
[[] []]
[[1]]
[[1 2]]
[[1 2] []]
[[1 2] [3]]
[[1 2] [3 4]]
[[1 2] [3 4] []]

func SplitUint64 added in v0.0.4

func SplitUint64(slice []uint64, sep uint64) (result [][]uint64)
Example
fmt.Println(SplitUint64([]uint64{}, 0))
fmt.Println(SplitUint64([]uint64{0}, 0))
fmt.Println(SplitUint64([]uint64{1}, 0))
fmt.Println(SplitUint64([]uint64{1, 2}, 0))
fmt.Println(SplitUint64([]uint64{1, 2, 0}, 0))
fmt.Println(SplitUint64([]uint64{1, 2, 0, 3}, 0))
fmt.Println(SplitUint64([]uint64{1, 2, 0, 3, 4}, 0))
fmt.Println(SplitUint64([]uint64{1, 2, 0, 3, 4, 0}, 0))
Output:

[]
[[] []]
[[1]]
[[1 2]]
[[1 2] []]
[[1 2] [3]]
[[1 2] [3 4]]
[[1 2] [3 4] []]

func SplitUint8 added in v0.0.4

func SplitUint8(slice []uint8, sep uint8) (result [][]uint8)
Example
fmt.Println(SplitUint8([]uint8{}, 0))
fmt.Println(SplitUint8([]uint8{0}, 0))
fmt.Println(SplitUint8([]uint8{1}, 0))
fmt.Println(SplitUint8([]uint8{1, 2}, 0))
fmt.Println(SplitUint8([]uint8{1, 2, 0}, 0))
fmt.Println(SplitUint8([]uint8{1, 2, 0, 3}, 0))
fmt.Println(SplitUint8([]uint8{1, 2, 0, 3, 4}, 0))
fmt.Println(SplitUint8([]uint8{1, 2, 0, 3, 4, 0}, 0))
Output:

[]
[[] []]
[[1]]
[[1 2]]
[[1 2] []]
[[1 2] [3]]
[[1 2] [3 4]]
[[1 2] [3 4] []]

func SplitValue added in v0.0.4

func SplitValue(slice reflect.Value, sep interface{}) reflect.Value
Example
fmt.Println(SplitValue(reflect.ValueOf([]T{}), T{}))
fmt.Println(SplitValue(reflect.ValueOf([]T{T{}}), T{}))
fmt.Println(SplitValue(reflect.ValueOf([]T{T{1, "a"}}), T{}))
fmt.Println(SplitValue(reflect.ValueOf([]T{T{1, "a"}, T{2, "b"}}), T{}))
fmt.Println(SplitValue(reflect.ValueOf([]T{T{1, "a"}, T{2, "b"}, T{}}), T{}))
fmt.Println(SplitValue(reflect.ValueOf([]T{T{1, "a"}, T{2, "b"}, T{}, T{3, "c"}}), T{}))
fmt.Println(SplitValue(reflect.ValueOf([]T{T{1, "a"}, T{2, "b"}, T{}, T{3, "c"}, T{4, "d"}}), T{}))
fmt.Println(SplitValue(reflect.ValueOf([]T{T{1, "a"}, T{2, "b"}, T{}, T{3, "c"}, T{4, "d"}, T{}}), T{}))
Output:

[]
[[] []]
[[{1 a}]]
[[{1 a} {2 b}]]
[[{1 a} {2 b}] []]
[[{1 a} {2 b}] [{3 c}]]
[[{1 a} {2 b}] [{3 c} {4 d}]]
[[{1 a} {2 b}] [{3 c} {4 d}] []]

func SubstractBool added in v0.1.0

func SubstractBool(left, right []bool) []bool

SubstractBool substracts right from left.

Example
fmt.Println(SubstractBool(nil, []bool{false}))
fmt.Println(SubstractBool([]bool{true, false, true}, []bool{false}))
fmt.Println(SubstractBool([]bool{true, false, true}, []bool{true, false}))
fmt.Println(SubstractBool([]bool{true, false, true}, nil))
fmt.Println(SubstractBool([]bool{true, false, true}, []bool{true}))
Output:

[]
[true true]
[]
[true false true]
[false]

func SubstractGeneric added in v0.0.5

func SubstractGeneric(left, right interface{}) interface{}

Substract substracts right from left.

Example
fmt.Println(SubstractGeneric(nil, []T{}))
fmt.Println(SubstractGeneric([]T{}, nil))
var left = []T{{3, "c"}, {}, {2, "b"}, {9, "f"}, {3, "c"}}
fmt.Println(SubstractGeneric(left, nil))
fmt.Println(SubstractGeneric(left, []T{{}, {2, "b"}, {2, "c"}}))
Output:

<nil>
[]
[{3 c} {0 } {2 b} {9 f} {3 c}]
[{3 c} {9 f} {3 c}]

func SubstractInt added in v0.0.4

func SubstractInt(left, right []int) []int

SubstractInt substracts right from left.

Example
fmt.Println(SubstractInt([]int{}, []int{2}))
fmt.Println(SubstractInt([]int{1, 2, 3, 1}, []int{2}))
fmt.Println(SubstractInt([]int{1, 2, 3, 1}, []int{1, 3, 4}))
fmt.Println(SubstractInt([]int{1, 2, 3, 1}, nil))
fmt.Println(SubstractInt([]int{1, 2, 3, 1}, []int{4}))
Output:

[]
[1 3 1]
[2]
[1 2 3 1]
[1 2 3 1]

func SubstractInt16 added in v0.0.4

func SubstractInt16(left, right []int16) []int16

SubstractInt16 substracts right from left.

Example
fmt.Println(SubstractInt16([]int16{}, []int16{2}))
fmt.Println(SubstractInt16([]int16{1, 2, 3, 1}, []int16{2}))
fmt.Println(SubstractInt16([]int16{1, 2, 3, 1}, []int16{1, 3, 4}))
fmt.Println(SubstractInt16([]int16{1, 2, 3, 1}, nil))
fmt.Println(SubstractInt16([]int16{1, 2, 3, 1}, []int16{4}))
Output:

[]
[1 3 1]
[2]
[1 2 3 1]
[1 2 3 1]

func SubstractInt32 added in v0.0.4

func SubstractInt32(left, right []int32) []int32

SubstractInt32 substracts right from left.

Example
fmt.Println(SubstractInt32([]int32{}, []int32{2}))
fmt.Println(SubstractInt32([]int32{1, 2, 3, 1}, []int32{2}))
fmt.Println(SubstractInt32([]int32{1, 2, 3, 1}, []int32{1, 3, 4}))
fmt.Println(SubstractInt32([]int32{1, 2, 3, 1}, nil))
fmt.Println(SubstractInt32([]int32{1, 2, 3, 1}, []int32{4}))
Output:

[]
[1 3 1]
[2]
[1 2 3 1]
[1 2 3 1]

func SubstractInt64 added in v0.0.4

func SubstractInt64(left, right []int64) []int64

SubstractInt64 substracts right from left.

Example
fmt.Println(SubstractInt64([]int64{}, []int64{2}))
fmt.Println(SubstractInt64([]int64{1, 2, 3, 1}, []int64{2}))
fmt.Println(SubstractInt64([]int64{1, 2, 3, 1}, []int64{1, 3, 4}))
fmt.Println(SubstractInt64([]int64{1, 2, 3, 1}, nil))
fmt.Println(SubstractInt64([]int64{1, 2, 3, 1}, []int64{4}))
Output:

[]
[1 3 1]
[2]
[1 2 3 1]
[1 2 3 1]

func SubstractInt8 added in v0.0.4

func SubstractInt8(left, right []int8) []int8

SubstractInt8 substracts right from left.

Example
fmt.Println(SubstractInt8([]int8{}, []int8{2}))
fmt.Println(SubstractInt8([]int8{1, 2, 3, 1}, []int8{2}))
fmt.Println(SubstractInt8([]int8{1, 2, 3, 1}, []int8{1, 3, 4}))
fmt.Println(SubstractInt8([]int8{1, 2, 3, 1}, nil))
fmt.Println(SubstractInt8([]int8{1, 2, 3, 1}, []int8{4}))
Output:

[]
[1 3 1]
[2]
[1 2 3 1]
[1 2 3 1]

func SubstractInterface added in v0.0.4

func SubstractInterface(left, right []interface{}) []interface{}

SubstractInterface substracts right from left.

Example
fmt.Println(SubstractInterface(nil, []interface{}{"a"}))
fmt.Println(SubstractInterface([]interface{}{"a", "b", 3, "a"}, []interface{}{"b"}))
fmt.Println(SubstractInterface([]interface{}{"a", "b", 3, "a"}, []interface{}{"a", 3, "d"}))
fmt.Println(SubstractInterface([]interface{}{"a", "b", 3, "a"}, nil))
fmt.Println(SubstractInterface([]interface{}{"a", "b", 3, "a"}, []interface{}{"d"}))
Output:

[]
[a 3 a]
[b]
[a b 3 a]
[a b 3 a]

func SubstractString added in v0.0.4

func SubstractString(left, right []string) []string

SubstractString substracts right from left.

Example
fmt.Println(SubstractString(nil, []string{"a"}))
fmt.Println(SubstractString([]string{"a", "b", "c", "a"}, []string{"b"}))
fmt.Println(SubstractString([]string{"a", "b", "c", "a"}, []string{"a", "c", "d"}))
fmt.Println(SubstractString([]string{"a", "b", "c", "a"}, nil))
fmt.Println(SubstractString([]string{"a", "b", "c", "a"}, []string{"d"}))
Output:

[]
[a c a]
[b]
[a b c a]
[a b c a]

func SubstractUint added in v0.0.4

func SubstractUint(left, right []uint) []uint

SubstractUint substracts right from left.

Example
fmt.Println(SubstractUint([]uint{}, []uint{2}))
fmt.Println(SubstractUint([]uint{1, 2, 3, 1}, []uint{2}))
fmt.Println(SubstractUint([]uint{1, 2, 3, 1}, []uint{1, 3, 4}))
fmt.Println(SubstractUint([]uint{1, 2, 3, 1}, nil))
fmt.Println(SubstractUint([]uint{1, 2, 3, 1}, []uint{4}))
Output:

[]
[1 3 1]
[2]
[1 2 3 1]
[1 2 3 1]

func SubstractUint16 added in v0.0.4

func SubstractUint16(left, right []uint16) []uint16

SubstractUint16 substracts right from left.

Example
fmt.Println(SubstractUint16([]uint16{}, []uint16{2}))
fmt.Println(SubstractUint16([]uint16{1, 2, 3, 1}, []uint16{2}))
fmt.Println(SubstractUint16([]uint16{1, 2, 3, 1}, []uint16{1, 3, 4}))
fmt.Println(SubstractUint16([]uint16{1, 2, 3, 1}, nil))
fmt.Println(SubstractUint16([]uint16{1, 2, 3, 1}, []uint16{4}))
Output:

[]
[1 3 1]
[2]
[1 2 3 1]
[1 2 3 1]

func SubstractUint32 added in v0.0.4

func SubstractUint32(left, right []uint32) []uint32

SubstractUint32 substracts right from left.

Example
fmt.Println(SubstractUint32([]uint32{}, []uint32{2}))
fmt.Println(SubstractUint32([]uint32{1, 2, 3, 1}, []uint32{2}))
fmt.Println(SubstractUint32([]uint32{1, 2, 3, 1}, []uint32{1, 3, 4}))
fmt.Println(SubstractUint32([]uint32{1, 2, 3, 1}, nil))
fmt.Println(SubstractUint32([]uint32{1, 2, 3, 1}, []uint32{4}))
Output:

[]
[1 3 1]
[2]
[1 2 3 1]
[1 2 3 1]

func SubstractUint64 added in v0.0.4

func SubstractUint64(left, right []uint64) []uint64

SubstractUint64 substracts right from left.

Example
fmt.Println(SubstractUint64([]uint64{}, []uint64{2}))
fmt.Println(SubstractUint64([]uint64{1, 2, 3, 1}, []uint64{2}))
fmt.Println(SubstractUint64([]uint64{1, 2, 3, 1}, []uint64{1, 3, 4}))
fmt.Println(SubstractUint64([]uint64{1, 2, 3, 1}, nil))
fmt.Println(SubstractUint64([]uint64{1, 2, 3, 1}, []uint64{4}))
Output:

[]
[1 3 1]
[2]
[1 2 3 1]
[1 2 3 1]

func SubstractUint8 added in v0.0.4

func SubstractUint8(left, right []uint8) []uint8

SubstractUint8 substracts right from left.

Example
fmt.Println(SubstractUint8([]uint8{}, []uint8{2}))
fmt.Println(SubstractUint8([]uint8{1, 2, 3, 1}, []uint8{2}))
fmt.Println(SubstractUint8([]uint8{1, 2, 3, 1}, []uint8{1, 3, 4}))
fmt.Println(SubstractUint8([]uint8{1, 2, 3, 1}, nil))
fmt.Println(SubstractUint8([]uint8{1, 2, 3, 1}, []uint8{4}))
Output:

[]
[1 3 1]
[2]
[1 2 3 1]
[1 2 3 1]

func SubstractValue added in v0.0.4

func SubstractValue(left, right reflect.Value) reflect.Value

SubstractValue substracts right from left.

Example
fmt.Println(SubstractValue(reflect.ValueOf([]T{}), reflect.ValueOf(nil)))
var left = []T{{3, "c"}, {}, {2, "b"}, {9, "f"}, {3, "c"}}
fmt.Println(SubstractValue(reflect.ValueOf(left), reflect.ValueOf(nil)))
fmt.Println(SubstractValue(reflect.ValueOf(left), reflect.ValueOf([]T{{}, {2, "b"}, {2, "c"}})))
Output:

[]
[{3 c} {0 } {2 b} {9 f} {3 c}]
[{3 c} {9 f} {3 c}]

func UnionBool added in v0.1.0

func UnionBool(left, right []bool) []bool

UnionBool returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionBool([]bool{true, false, true}, []bool{}))
fmt.Println(UnionBool([]bool{true, true}, []bool{false}))
Output:

[true false true]
[true true false]

func UnionGeneric added in v0.0.5

func UnionGeneric(left, right interface{}) interface{}

UnionGeneric returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionGeneric(nil, nil))

var left = []T{{3, "c"}, {}, {2, "b"}, {9, "f"}, {2, "b"}}
fmt.Println(UnionGeneric(left, nil))
fmt.Println(UnionGeneric(nil, []T{{3, "c"}, {3, "c"}}))
fmt.Println(UnionGeneric(left, []int64{}))
fmt.Println(UnionGeneric(left, []T{{}, {2, "b"}, {4, "d"}}))
Output:

<nil>
[{3 c} {0 } {2 b} {9 f} {2 b}]
[{3 c}]
[{3 c} {0 } {2 b} {9 f} {2 b}]
[{3 c} {0 } {2 b} {9 f} {2 b} {4 d}]

func UnionInt added in v0.0.4

func UnionInt(left, right []int) []int

UnionInt returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionInt([]int{1, 2, 2, 3}, []int{3, 4, 3, 4}))
Output:

[1 2 2 3 4]

func UnionInt16 added in v0.0.4

func UnionInt16(left, right []int16) []int16

UnionInt16 returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionInt16([]int16{1, 2, 2, 3}, []int16{3, 4, 3, 4}))
Output:

[1 2 2 3 4]

func UnionInt32 added in v0.0.4

func UnionInt32(left, right []int32) []int32

UnionInt32 returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionInt32([]int32{1, 2, 2, 3}, []int32{3, 4, 3, 4}))
Output:

[1 2 2 3 4]

func UnionInt64 added in v0.0.4

func UnionInt64(left, right []int64) []int64

UnionInt64 returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionInt64([]int64{1, 2, 2, 3}, []int64{3, 4, 3, 4}))
Output:

[1 2 2 3 4]

func UnionInt8 added in v0.0.4

func UnionInt8(left, right []int8) []int8

UnionInt8 returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionInt8([]int8{1, 2, 2, 3}, []int8{3, 4, 3, 4}))
Output:

[1 2 2 3 4]

func UnionInterface added in v0.0.4

func UnionInterface(left, right []interface{}) []interface{}

UnionInterface returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionInterface([]interface{}{1, 2, 2, "3"}, []interface{}{"3", "4", "3", 4}))
Output:

[1 2 2 3 4 4]

func UnionString

func UnionString(left, right []string) []string

UnionString returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionString([]string{"1", "2", "2", "3"}, []string{"3", "4", "3", "4"}))
Output:

[1 2 2 3 4]

func UnionUint added in v0.0.4

func UnionUint(left, right []uint) []uint

UnionUint returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionUint([]uint{1, 2, 2, 3}, []uint{3, 4, 3, 4}))
Output:

[1 2 2 3 4]

func UnionUint16 added in v0.0.4

func UnionUint16(left, right []uint16) []uint16

UnionUint16 returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionUint16([]uint16{1, 2, 2, 3}, []uint16{3, 4, 3, 4}))
Output:

[1 2 2 3 4]

func UnionUint32 added in v0.0.4

func UnionUint32(left, right []uint32) []uint32

UnionUint32 returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionUint32([]uint32{1, 2, 2, 3}, []uint32{3, 4, 3, 4}))
Output:

[1 2 2 3 4]

func UnionUint64 added in v0.0.4

func UnionUint64(left, right []uint64) []uint64

UnionUint64 returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionUint64([]uint64{1, 2, 2, 3}, []uint64{3, 4, 3, 4}))
Output:

[1 2 2 3 4]

func UnionUint8 added in v0.0.4

func UnionUint8(left, right []uint8) []uint8

UnionUint8 returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionUint8([]uint8{1, 2, 2, 3}, []uint8{3, 4, 3, 4}))
Output:

[1 2 2 3 4]

func UnionValue added in v0.0.4

func UnionValue(left, right reflect.Value) reflect.Value

UnionValue returns union set of left and right, with right follows left. The duplicate members in left are kept.

Example
fmt.Println(UnionValue(reflect.ValueOf(nil), reflect.ValueOf(nil)).IsValid())
Output:

false

func UniqueBool added in v0.1.0

func UniqueBool(slice []bool) []bool

Input slice will be modified.

Example
fmt.Println(UniqueBool([]bool{true, true, false}))
Output:

[true false]

func UniqueBy added in v0.0.4

func UniqueBy(slice interface{}, keyFunc func(i int) interface{}, keepLast bool) interface{}

UniqueBy will change the original slice, Use copy to keep the original slice. The input slice will be modified. If param keepLast is true, the last one of the same elements is kept, otherwise the first one is kept.

Example
slice := []T{}
fmt.Println(UniqueBy(slice, func(i int) interface{} { return slice[i].Id }, false))

slice = []T{{1, `a`}, {1, `b`}, {2, `a`}, {2, `b`}}
fmt.Println(UniqueBy(slice, func(i int) interface{} { return slice[i].Id }, false))
Output:

[]
[{1 a} {2 a}]
Example (KeepLast)
slice := []T{}
fmt.Println(UniqueBy(slice, func(i int) interface{} { return slice[i].Id }, true))

slice = []T{{1, `a`}, {1, `b`}, {2, `a`}, {2, `b`}}
fmt.Println(UniqueBy(slice, func(i int) interface{} { return slice[i].Id }, true))
Output:

[]
[{1 b} {2 b}]

func UniqueByValue added in v0.0.4

func UniqueByValue(slice reflect.Value, keyFunc func(i int) interface{}, keepLast bool) reflect.Value

UniqueByValue will change the original slice, Use copy to keep the original slice. The input slice will be modified. If param keepLast is true, the last one of the same elements is kept, otherwise the first one is kept.

func UniqueField

func UniqueField(slice interface{}, fieldPaths ...string) (result []interface{})

UniqueField returns unique values of field from a struct slice

Example
slice := []T{{1, "a"}, {2, "a"}, {1, "b"}, {3, "c"}}
fmt.Println(UniqueField(slice, "Id"))
fmt.Println(UniqueField(slice, "Name"))
Output:

[1 2 3]
[a b c]

func UniqueFieldBool added in v0.1.0

func UniqueFieldBool(slice interface{}, fieldPaths ...string) (result []bool)

UniqueFieldBool returns unique values of field from a struct slice

Example
type t struct{ Flag bool }
slice := []t{{true}, {true}}
fmt.Println(UniqueFieldBool(slice, "Flag"))
Output:

[true]

func UniqueFieldInt added in v0.0.4

func UniqueFieldInt(slice interface{}, fieldPaths ...string) (result []int)

UniqueFieldInt returns unique values of field from a struct slice

Example
slice := []T{{1, "a"}, {2, "a"}, {1, "b"}, {3, "c"}}
fmt.Println(UniqueFieldInt(slice, "Id"))
Output:

[1 2 3]

func UniqueFieldInt16 added in v0.0.4

func UniqueFieldInt16(slice interface{}, fieldPaths ...string) (result []int16)

UniqueFieldInt16 returns unique values of field from a struct slice

Example
slice := []T{{1, "a"}, {2, "a"}, {1, "b"}, {3, "c"}}
fmt.Println(UniqueFieldInt16(slice, "Id"))
Output:

[1 2 3]

func UniqueFieldInt32 added in v0.0.4

func UniqueFieldInt32(slice interface{}, fieldPaths ...string) (result []int32)

UniqueFieldInt32 returns unique values of field from a struct slice

Example
slice := []T{{1, "a"}, {2, "a"}, {1, "b"}, {3, "c"}}
fmt.Println(UniqueFieldInt32(slice, "Id"))
Output:

[1 2 3]

func UniqueFieldInt64 added in v0.0.4

func UniqueFieldInt64(slice interface{}, fieldPaths ...string) (result []int64)

UniqueFieldInt64 returns unique values of field from a struct slice

Example
slice := []T{{1, "a"}, {2, "a"}, {1, "b"}, {3, "c"}}
fmt.Println(UniqueFieldInt64(slice, "Id"))
Output:

[1 2 3]

func UniqueFieldInt8 added in v0.0.4

func UniqueFieldInt8(slice interface{}, fieldPaths ...string) (result []int8)

UniqueFieldInt8 returns unique values of field from a struct slice

Example
slice := []T{{1, "a"}, {2, "a"}, {1, "b"}, {3, "c"}}
fmt.Println(UniqueFieldInt8(slice, "Id"))
Output:

[1 2 3]

func UniqueFieldString added in v0.0.4

func UniqueFieldString(slice interface{}, fieldPaths ...string) (result []string)

UniqueFieldString returns unique values of field from a struct slice

Example
slice := []T{{1, "a"}, {2, "a"}, {1, "b"}, {3, "c"}}
fmt.Println(UniqueFieldString(slice, "Name"))
Output:

[a b c]

func UniqueFieldUint added in v0.0.4

func UniqueFieldUint(slice interface{}, fieldPaths ...string) (result []uint)

UniqueFieldUint returns unique values of field from a struct slice

Example
slice := []struct{ inner }{{inner{1}}, {inner{1}}, {inner{2}}, {inner{3}}, {inner{3}}}
fmt.Println(UniqueFieldUint(slice, "inner", "Uint"))
Output:

[1 2 3]

func UniqueFieldUint16 added in v0.0.4

func UniqueFieldUint16(slice interface{}, fieldPaths ...string) (result []uint16)

UniqueFieldUint16 returns unique values of field from a struct slice

Example
slice := []struct{ inner }{{inner{1}}, {inner{1}}, {inner{2}}, {inner{3}}, {inner{3}}}
fmt.Println(UniqueFieldUint16(slice, "inner", "Uint"))
Output:

[1 2 3]

func UniqueFieldUint32 added in v0.0.4

func UniqueFieldUint32(slice interface{}, fieldPaths ...string) (result []uint32)

UniqueFieldUint32 returns unique values of field from a struct slice

Example
slice := []struct{ inner }{{inner{1}}, {inner{1}}, {inner{2}}, {inner{3}}, {inner{3}}}
fmt.Println(UniqueFieldUint32(slice, "inner", "Uint"))
Output:

[1 2 3]

func UniqueFieldUint64 added in v0.0.4

func UniqueFieldUint64(slice interface{}, fieldPaths ...string) (result []uint64)

UniqueFieldUint64 returns unique values of field from a struct slice

Example
slice := []struct{ inner }{{inner{1}}, {inner{1}}, {inner{2}}, {inner{3}}, {inner{3}}}
fmt.Println(UniqueFieldUint64(slice, "inner", "Uint"))
Output:

[1 2 3]

func UniqueFieldUint8 added in v0.0.4

func UniqueFieldUint8(slice interface{}, fieldPaths ...string) (result []uint8)

UniqueFieldUint8 returns unique values of field from a struct slice

Example
slice := []struct{ inner }{{inner{1}}, {inner{1}}, {inner{2}}, {inner{3}}, {inner{3}}}
fmt.Println(UniqueFieldUint8(slice, "inner", "Uint"))
Output:

[1 2 3]

func UniqueGeneric added in v0.0.5

func UniqueGeneric(slice interface{}) interface{}

Input slice will be modified.

Example
fmt.Println(UniqueGeneric([]T{{1, `a`}, {2, `b`}, {}, {3, `c`}, {2, `b`}, {3, `c`}}))
Output:

[{1 a} {2 b} {0 } {3 c}]

func UniqueInt

func UniqueInt(slice []int) []int

Input slice will be modified.

Example
fmt.Println(UniqueInt([]int{0, 1, 1, 2, 2, 3, 3, 4}))
Output:

[0 1 2 3 4]

func UniqueInt16 added in v0.0.4

func UniqueInt16(slice []int16) []int16

Input slice will be modified.

Example
fmt.Println(UniqueInt16([]int16{0, 1, 1, 2, 2, 3, 3, 4}))
Output:

[0 1 2 3 4]

func UniqueInt32 added in v0.0.4

func UniqueInt32(slice []int32) []int32

Input slice will be modified.

Example
fmt.Println(UniqueInt32([]int32{0, 1, 1, 2, 2, 3, 3, 4}))
Output:

[0 1 2 3 4]

func UniqueInt64

func UniqueInt64(slice []int64) []int64

Input slice will be modified.

Example
fmt.Println(UniqueInt64([]int64{0, 1, 1, 2, 2, 3, 3, 4}))
Output:

[0 1 2 3 4]

func UniqueInt8 added in v0.0.4

func UniqueInt8(slice []int8) []int8

Input slice will be modified.

Example
fmt.Println(UniqueInt8([]int8{0, 1, 1, 2, 2, 3, 3, 4}))
Output:

[0 1 2 3 4]

func UniqueInterface added in v0.0.4

func UniqueInterface(slice []interface{}) []interface{}

Input slice will be modified.

Example
fmt.Println(UniqueInterface([]interface{}{0, 1, 1, `2`, `2`, true, true, 4}))
Output:

[0 1 2 true 4]

func UniqueString

func UniqueString(slice []string) []string

Input slice will be modified.

Example
fmt.Println(UniqueString([]string{`0`, `a`, `a`, `b`, `b`, `c`, `c`, `d`}))
Output:

[0 a b c d]

func UniqueUint added in v0.0.4

func UniqueUint(slice []uint) []uint

Input slice will be modified.

Example
fmt.Println(UniqueUint([]uint{0, 1, 1, 2, 2, 3, 3, 4}))
Output:

[0 1 2 3 4]

func UniqueUint16 added in v0.0.4

func UniqueUint16(slice []uint16) []uint16

Input slice will be modified.

Example
fmt.Println(UniqueUint16([]uint16{0, 1, 1, 2, 2, 3, 3, 4}))
Output:

[0 1 2 3 4]

func UniqueUint32 added in v0.0.4

func UniqueUint32(slice []uint32) []uint32

Input slice will be modified.

Example
fmt.Println(UniqueUint32([]uint32{0, 1, 1, 2, 2, 3, 3, 4}))
Output:

[0 1 2 3 4]

func UniqueUint64 added in v0.0.4

func UniqueUint64(slice []uint64) []uint64

Input slice will be modified.

Example
fmt.Println(UniqueUint64([]uint64{0, 1, 1, 2, 2, 3, 3, 4}))
Output:

[0 1 2 3 4]

func UniqueUint8 added in v0.0.4

func UniqueUint8(slice []uint8) []uint8

Input slice will be modified.

Example
fmt.Println(UniqueUint8([]uint8{0, 1, 1, 2, 2, 3, 3, 4}))
Output:

[0 1 2 3 4]

func UniqueValue added in v0.0.4

func UniqueValue(slice reflect.Value) reflect.Value

Input slice will be modified.

Example
fmt.Println(UniqueValue(reflect.ValueOf(&[]T{{1, `a`}, {2, `b`}, {}, {3, `c`}, {2, `b`}, {3, `c`}})))
Output:

[{1 a} {2 b} {0 } {3 c}]

Types

This section is empty.

Jump to

Keyboard shortcuts

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