Documentation ¶
Overview ¶
Package unique implements type-specific functions to deduplicate a slice and return a slice with only the unique elements in it. It uses an intermediate map to store values already seen in the slice, then returns the new slice. Note that no guarantees are made about ordering.
Index ¶
- func Float32s(input []float32) []float32
- func Float64s(input []float64) []float64
- func Int32s(input []int32) []int32
- func Int64s(input []int64) []int64
- func Ints(input []int) []int
- func Strings(input []string) []string
- func UInt32s(input []uint32) []uint32
- func UInt64s(input []uint64) []uint64
- func UInts(input []uint) []uint
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Float32s ¶
Float32s returns a slice of float32 without any duplicates in it.
Example ¶
vals := []float32{1.2, 2.2, 3.3, 1.2, 2.2, 3.1, 1.2, 2.2, 3.1, 3.3, 1.2} deduped := Float32s(vals) fmt.Println(deduped)
Output: [1.2 2.2 3.3 3.1]
func Float64s ¶
Float64s returns a slice of float64 without any duplicates in it.
Example ¶
vals := []float64{1.2, 2.2, 3.3, 1.2, 2.2, 3.1, 1.2, 2.2, 3.1, 3.3, 1.2} deduped := Float64s(vals) fmt.Println(deduped)
Output: [1.2 2.2 3.3 3.1]
func Int32s ¶
Int32s returns a slice of int32 without any duplicates in it.
Example ¶
vals := []int32{-3, -2, -1, 1, 2, -3, 1, -2, 3, 1, 2, 3, 4, 5} deduped := Int32s(vals) fmt.Println(deduped)
Output: [-3 -2 -1 1 2 3 4 5]
func Int64s ¶
Int64s returns a slice of int64 without any duplicates in it.
Example ¶
vals := []int64{-3, -2, -1, 1, 2, -3, 1, -2, 3, 1, 2, 3, 4, 5} deduped := Int64s(vals) fmt.Println(deduped)
Output: [-3 -2 -1 1 2 3 4 5]
func Ints ¶
Ints returns a slice of ints without any duplicates in it.
Example ¶
vals := []int{-3, -2, -1, 1, 2, -3, 1, -2, 3, 1, 2, 3, 4, 5} deduped := Ints(vals) fmt.Println(deduped)
Output: [-3 -2 -1 1 2 3 4 5]
func Strings ¶
Strings returns a slice of strings without any duplicates in it.
Example ¶
vals := []string{"foo", "bar", "foo", "baz", "bar", "zap", "foo"} deduped := Strings(vals) fmt.Println(deduped)
Output: [foo bar baz zap]
func UInt32s ¶
UInt32s returns a slice of uint32 without any duplicates in it.
Example ¶
vals := []uint32{1, 2, 3, 1, 2, 3, 1, 2, 3, 4, 5} deduped := UInt32s(vals) fmt.Println(deduped)
Output: [1 2 3 4 5]
Types ¶
This section is empty.