slices

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2022 License: Apache-2.0 Imports: 1 Imported by: 1

Documentation

Overview

Package slices provides additional slice functions on common slice types

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolSlicesEqual

func BoolSlicesEqual(a, b []bool) bool

BoolSlicesEqual returns true only if the contents of the 2 slices are the same

func ByteSlicesEqual

func ByteSlicesEqual(a, b []byte) bool

ByteSlicesEqual returns true only if the contents of the 2 slices are the same

func CloneStrings

func CloneStrings(src []string) []string

CloneStrings will return an independnt copy of the src slice, it preserves the distinction between a nil value and an empty slice.

func ContainsString

func ContainsString(items []string, item string) bool

ContainsString returns true if the items slice contains a value equal to item Note that this can end up traversing the entire slice, and so is only really suitable for small slices, for larger data sets, consider using a map instead.

func ContainsStringEqualFold

func ContainsStringEqualFold(items []string, item string) bool

ContainsStringEqualFold returns true if the items slice contains a value equal to item ignoring case [i.e. using EqualFold] Note that this can end up traversing the entire slice, and so is only really suitable for small slices, for larger data sets, consider using a map instead.

func Float64SlicesEqual

func Float64SlicesEqual(a, b []float64) bool

Float64SlicesEqual returns true only if the contents of the 2 slices are the same

func Int64SlicesEqual

func Int64SlicesEqual(a, b []int64) bool

Int64SlicesEqual returns true only if the contents of the 2 slices are the same

func MapStringSlice

func MapStringSlice(items []string, mapFn func(in string) string) []string

MapStringSlice returns a new slices of strings that is the result of applies mapFn to each string in the input slice.

func NvlInt

func NvlInt(items ...int) int

NvlInt returns the first value from the supplied list that is not 0, or 0 if there are no values that are not zero

func NvlInt64

func NvlInt64(items ...int64) int64

NvlInt64 returns the first value from the supplied list that is not 0, or 0 if there are no values that are not zero

func NvlString

func NvlString(items ...string) string

NvlString returns the first string from the supplied list that has len() > 0 or "" if all the strings are empty

func NvlUint64

func NvlUint64(items ...uint64) uint64

NvlUint64 returns the first item from the list that is not 0, or 0 if there are no values that are not zero

func Prefixed

func Prefixed(prefix string, items []string) []string

Prefixed returns a new slice of strings with each input item prefixed by the supplied prefix e.g. Prefixed("foo", []string{"bar","bob"}) would return []string{"foobar", "foobob"} the input slice is not modified.

func Quoted

func Quoted(items []string) []string

Quoted returns a new slice of strings where each input stream has been wrapped in quotes

func StringContainsOneOf

func StringContainsOneOf(item string, items []string) bool

StringContainsOneOf returns true if one of items slice is a substring of specified value.

func StringSlicesEqual

func StringSlicesEqual(a, b []string) bool

StringSlicesEqual returns true only if the contents of the 2 slices are the same

func Suffixed

func Suffixed(suffix string, items []string) []string

Suffixed returns a new slice of strings which each input item suffixed by the supplied suffix e.g. Suffixed("foo", []string{"bar","bob"}) would return []string{"barfoo", "bobfoo"} the input slice is not modified

func Uint64SlicesEqual

func Uint64SlicesEqual(a, b []uint64) bool

Uint64SlicesEqual returns true only if the contents of the 2 slices are the same

Types

type Uint64s

type Uint64s []uint64

Uint64s is a slice of uint64, that knows how to be sorted, using sort.Sort

func (Uint64s) Len

func (a Uint64s) Len() int

Len returns the length of the slice, as required by sort.Interface

func (Uint64s) Less

func (a Uint64s) Less(i, j int) bool

Less returns the true if the value at index i is smaller than the value at index j, as required by sort.Interface

func (Uint64s) Swap

func (a Uint64s) Swap(i, j int)

Swap swaps the values at the indicated indexes, as required by sort.Interface

Jump to

Keyboard shortcuts

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