slice

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[T comparable](s []T, v T) bool

Contains returns true is the element v is contained in the slice s.

func Delete

func Delete(s []string, toDelete []string) (str []string)

Delete removes the elements in toDelete from slice s.

func Diff

func Diff(s, t []string) []string

Diff checks if s in contained within t and if t is contained within s. Diff returns all elements that are not in the intersection of s and t.

func Filter

func Filter[T constraints.Ordered](slice []T, predicateFunc Predicate[T]) []T

Filter takes a generic slice and a predicate func and returns a slice of all elements in the original slice that satisfy the predicate

func LeftDiff

func LeftDiff(s, t []string) []string

LeftDiff checks if t is contained within s and returns all elements not is s.

func UnorderedEqual

func UnorderedEqual[T constraints.Ordered](a, b []T) bool

UnorderedEqual determines if two slices of the same type contain equal elements ignoring ordering the ordered constraint ensures only ints, floats and strings are usable with this function.

Types

type Predicate

type Predicate[T constraints.Ordered] func(elem T) bool

Predicate defines the expected filter functions Filter accepts

func StartsWithString

func StartsWithString(prefix string) Predicate[string]

StartsWithString returns true if the predicate string starts with the provided prefix

Jump to

Keyboard shortcuts

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