util

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFlagAliasesBool

func AddFlagAliasesBool(flags *pflag.FlagSet, originalFlag string, aliasMap map[string][]string, aliases ...string)

func AddFlagAliasesString

func AddFlagAliasesString(flags *pflag.FlagSet, originalFlag string, aliasMap map[string][]string, aliases ...string)

func AddFlagAliasesStringSlice added in v0.2.1

func AddFlagAliasesStringSlice(flags *pflag.FlagSet, originalFlag string, aliasMap map[string][]string, aliases ...string)

func Any added in v0.6.0

func Any[T any](items []T) bool

func ApplyFlagAliases added in v0.2.1

func ApplyFlagAliases(flags *pflag.FlagSet, aliases map[string][]string)

func Empty added in v0.6.0

func Empty[T any](items []T) bool

func ExtractValuesMatchingKeys

func ExtractValuesMatchingKeys[T any](collection []T, keys []string, idSelector func(T) string, valueSelector func(T) string) []string

ExtractValuesMatchingKeys returns a collection of values which matched a specified set of keys, in the exact order of keys. Given a collection of items, and a collection of keys to match within that collection This makes no sense, hopefully an example helps: - Given an array of Channels [<id:C1, name:'C1Name'>, <id:C7, name:'C7Name'> , <id:C2, name:'C2Name'>] - And a set of keys [C2, C7] - Returns the extracted values ['C2Name', 'C7Name']

Note: if something can't be found, then the extracted values collection will contain a zero value in-place

func IsCalledFromPipe added in v0.5.0

func IsCalledFromPipe() bool

func MapCollectionWithLookups

func MapCollectionWithLookups[T any, TResult any](
	cacheContainer *MapCollectionCacheContainer,
	collection []T,
	keySelector func(T) []string,
	mapper func(T, []string) TResult,
	runLookups ...func([]string) ([]string, error),
) ([]TResult, error)

MapCollectionWithLookups does a 'map' operation over the collection, transforming each input row into an output row according to `mapper`, however it also provides the ability to collect ID's of related items as it iterates the collection, and call out to lambdas to look those values up. See the unit tests for examples which should clarify the use-cases for this.

func ReadValuesFromPipe added in v0.5.0

func ReadValuesFromPipe() []string

ReadValuesFromPipe will return an array of strings from the pipe input separated by new line.

func RemoveIndex added in v1.1.0

func RemoveIndex[T any](s []T, index int) []T

func SliceContains

func SliceContains[T comparable](slice []T, target T) bool

SliceContains returns true if it finds an item in the slice that is equal to the target

func SliceContainsAny added in v0.2.1

func SliceContainsAny[T comparable](slice []T, predicate func(item T) bool) bool

SliceContainsAny returns true if it finds an item in the slice where `predicate` returns true

func SliceDistinct added in v1.0.0

func SliceDistinct[T comparable](slice []T) []T

func SliceExcept added in v1.2.0

func SliceExcept[T any](slice []T, predicate func(item T) bool) []T

func SliceFilter

func SliceFilter[T any](slice []T, predicate func(item T) bool) []T

SliceFilter takes an input collection and returns elements where `predicate` returns true Known as 'filter' in most other languages or 'Select' in C# Linq.

func SliceTransform

func SliceTransform[T any, TResult any](slice []T, transform func(item T) TResult) []TResult

SliceTransform takes an input collection, applies the transform function to each row, and returns the output. Known as 'map' in most other languages or 'Select' in C# Linq.

Types

type MapCollectionCacheContainer

type MapCollectionCacheContainer struct {
	Caches []map[string]string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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