slices

package
v0.6.37 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 5 Imported by: 11

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 Contains added in v0.4.1

func Contains[T comparable](arr []T, val T) bool

Contains returns true if val is in arr, and false otherwise.

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 Deduplicate added in v0.4.1

func Deduplicate[E comparable](slice []E) []E

Deduplicate returns a deduplicated slice.

func Float64SlicesEqual

func Float64SlicesEqual(a, b []float64) bool

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

func HashStrings added in v0.4.1

func HashStrings(values ...string) string

HashStrings returns the base64 SHA-1 of a series of string values

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 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 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 Replace added in v0.4.1

func Replace[E comparable](slice []E, old, new E)

Replace replaces all occurrences of old with new in slice.

func StringArrayToMap added in v0.4.1

func StringArrayToMap(arr []string) (map[string]string, error)

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 StringStartsWithOneOf

func StringStartsWithOneOf(value string, items []string) bool

StringStartsWithOneOf returns true if one of items slice is a prefix of specified value.

func StringUpto

func StringUpto(str string, max int) string

StringUpto returns the beginning of the string up to `max`

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 Truncate added in v0.4.1

func Truncate[T any](arr []T, maxLen uint) []T

Truncate returns a new slice containing the first maxLen elements of arr. If maxLen is greater than the length of arr, arr is returned.

func Uint64SlicesEqual

func Uint64SlicesEqual(a, b []uint64) bool

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

func UniqueStrings

func UniqueStrings(dups []string) []string

UniqueStrings removes duplicates from the given list

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