xgslice

package
v0.0.0-...-241b93c Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: MIT Imports: 5 Imported by: 0

README

xgslice (generic slice)

Dependencies

  • xgeneric/xsugar
  • xgeneric/xtuple

Documents

Types
  • type Equaller[T any] func
  • type Lesser[T any] func
Variables
  • None
Constants
  • None
Functions
  • func ShuffleSelf[T any](slice []T)
  • func Shuffle[S ~[]T, T any](slice S) S
  • func ReverseSelf[T any](slice []T)
  • func Reverse[S ~[]T, T any](slice S) S
  • func SortSelf[T xsugar.Ordered](slice []T)
  • func Sort[S ~[]T, T xsugar.Ordered](slice S) S
  • func SortSelfWith[T any](slice []T, less Lesser[T])
  • func SortWith[S ~[]T, T any](slice S, less Lesser[T]) S
  • func StableSortSelf[T xsugar.Ordered](slice []T)
  • func StableSort[S ~[]T, T xsugar.Ordered](slice S) S
  • func StableSortSelfWith[T any](slice []T, less Lesser[T])
  • func StableSortWith[S ~[]T, T any](slice S, less Lesser[T]) S
  • func IndexOf[T comparable](slice []T, value T) int
  • func IndexOfWith[T any](slice []T, value T, equaller Equaller[T]) int
  • func LastIndexOf[T comparable](slice []T, value T) int
  • func LastIndexOfWith[T any](slice []T, value T, equaller Equaller[T]) int
  • func Contains[T comparable](slice []T, value T) bool
  • func ContainsWith[T any](slice []T, value T, equaller Equaller[T]) bool
  • func Count[T comparable](slice []T, value T) int
  • func CountWith[T any](slice []T, value T, equaller Equaller[T]) int
  • func Insert[S ~[]T, T any](slice S, index int, values ...T) S
  • func InsertSelf[S ~[]T, T any](slice S, index int, values ...T) S
  • func Delete[S ~[]T, T comparable](slice S, value T, n int, capArg ...int) S
  • func DeleteWith[S ~[]T, T any](slice S, value T, n int, equaller Equaller[T], capArg ...int) S
  • func DeleteAll[S ~[]T, T comparable](slice S, value T, capArg ...int) S
  • func DeleteAllWith[S ~[]T, T any](slice S, value T, equaller Equaller[T], capArg ...int) S
  • func DeleteSelf[S ~[]T, T comparable](slice S, value T, n int) S
  • func DeleteSelfWith[S ~[]T, T any](slice S, value T, n int, equaller Equaller[T]) S
  • func DeleteAllSelf[S ~[]T, T comparable](slice S, value T) S
  • func DeleteAllSelfWith[S ~[]T, T any](slice S, value T, equaller Equaller[T]) S
  • func ContainsAll[T comparable](list, subset []T) bool
  • func ContainsAllWith[T any](list, subset []T, equaller Equaller[T]) bool
  • func Diff[S ~[]T, T comparable](slice1, slice2 S, capArg ...int) S
  • func DiffWith[S ~[]T, T any](slice1, slice2 S, equaller Equaller[T], capArg ...int) S
  • func Union[S ~[]T, T comparable](slice1, slice2 S, capArg ...int) S
  • func UnionWith[S ~[]T, T any](slice1, slice2 S, equaller Equaller[T], capArg ...int) S
  • func Intersect[S ~[]T, T comparable](slice1, slice2 S, capArg ...int) S
  • func IntersectWith[S ~[]T, T any](slice1, slice2 S, equaller Equaller[T], capArg ...int) S
  • func Deduplicate[T comparable, S ~[]T](slice S, capArg ...int) S
  • func DeduplicateWith[S ~[]T, T any](slice S, equaller Equaller[T], capArg ...int) S
  • func DeduplicateSelf[S ~[]T, T comparable](slice S) S
  • func DeduplicateSelfWith[S ~[]T, T any](slice S, equaller Equaller[T]) S
  • func Compact[S ~[]T, T comparable](slice S, capArg ...int) S
  • func CompactWith[S ~[]T, T any](slice S, equaller Equaller[T], capArg ...int) S
  • func CompactSelf[S ~[]T, T comparable](slice S) S
  • func CompactSelfWith[S ~[]T, T any](slice S, equaller Equaller[T]) S
  • func Equal[T comparable](slice1, slice2 []T) bool
  • func EqualWith[T1, T2 any](slice1 []T1, slice2 []T2, equaller Equaller2[T1, T2]) bool
  • func ElementMatch[T comparable](slice1, slice2 []T) bool
  • func ElementMatchWith[T1, T2 any](slice1 []T1, slice2 []T2, equaller Equaller2[T1, T2]) bool
  • func Repeat[T any](value T, count uint) []T
  • func Foreach[T any](slice []T, f func(T))
  • func Map[T1, T2 any](slice []T1, f func(T1) T2) []T2
  • func Expand[T1, T2 any](slice []T1, f func(T1) []T2, capArg ...int) []T2
  • func Reduce[T, U any](slice []T, initial U, f func(U, T) U) U
  • func Filter[S ~[]T, T any](slice S, f func(T) bool, capArg ...int) S
  • func Any[T any](slice []T, f func(T) bool) bool
  • func All[T any](slice []T, f func(T) bool) bool
  • func Zip[T1, T2 any](slice1 []T1, slice2 []T2) []xtuple.Tuple[T1, T2]
  • func Zip3[T1, T2, T3 any](slice1 []T1, slice2 []T2, slice3 []T3) []xtuple.Triple[T1, T2, T3]
  • func Unzip[T1, T2 any](slice []xtuple.Tuple[T1, T2]) ([]T1, []T2)
  • func Unzip3[T1, T2, T3 any](slice []xtuple.Triple[T1, T2, T3]) ([]T1, []T2, []T3)
  • func Clone[S ~[]T, T any](slice S) S
  • func Clip[S ~[]T, T any](slice S) S
  • func Grow[S ~[]T, T any](slice S, n int) S
Methods
  • None

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](slice []T, f func(T) bool) bool

All checks whether items from given slice that all satisfied given predicate function.

func Any

func Any[T any](slice []T, f func(T) bool) bool

Any checks whether given slice contains an item that satisfied given predicate function.

func Clip

func Clip[S ~[]T, T any](slice S) S

Clip removes unused capacity from given slice, returning slice[:len(s):len(s)].

func Clone

func Clone[S ~[]T, T any](slice S) S

Clone returns a copy of given slice, and the elements are copied using assignment.

func Compact

func Compact[S ~[]T, T comparable](slice S, capArg ...int) S

Compact removes the duplicate items in neighbor from []T slice.

func CompactSelf

func CompactSelf[S ~[]T, T comparable](slice S) S

CompactSelf removes the duplicate items in neighbor from []T slice, by modifying given slice directly.

func CompactSelfWith

func CompactSelfWith[S ~[]T, T any](slice S, equaller Equaller[T]) S

CompactSelfWith removes the duplicate items in neighbor from []T slice with Equaller, by modifying given slice directly.

func CompactWith

func CompactWith[S ~[]T, T any](slice S, equaller Equaller[T], capArg ...int) S

CompactWith removes the duplicate items in neighbor from []T slice with Equaller.

func Contains

func Contains[T comparable](slice []T, value T) bool

Contains returns true if value is in the []T slice.

func ContainsAll

func ContainsAll[T comparable](list, subset []T) bool

ContainsAll returns true if values in []T subset are all in the []T list.

func ContainsAllWith

func ContainsAllWith[T any](list, subset []T, equaller Equaller[T]) bool

ContainsAllWith returns true if values in []T subset are all in the []T list with Equaller.

func ContainsWith

func ContainsWith[T any](slice []T, value T, equaller Equaller[T]) bool

ContainsWith returns true if value is in the []T slice with Equaller.

func Count

func Count[T comparable](slice []T, value T) int

Count returns the count of value in the []T slice.

func CountWith

func CountWith[T any](slice []T, value T, equaller Equaller[T]) int

CountWith returns the count of value in the []T slice with Equaller.

func Deduplicate

func Deduplicate[T comparable, S ~[]T](slice S, capArg ...int) S

Deduplicate removes the duplicate items from []T slice as a set.

func DeduplicateSelf

func DeduplicateSelf[S ~[]T, T comparable](slice S) S

DeduplicateSelf removes the duplicate items from []T slice as a set, by modifying given slice directly.

func DeduplicateSelfWith

func DeduplicateSelfWith[S ~[]T, T any](slice S, equaller Equaller[T]) S

DeduplicateSelfWith removes the duplicate items from []T slice as a set with Equaller, by modifying given slice directly.

func DeduplicateWith

func DeduplicateWith[S ~[]T, T any](slice S, equaller Equaller[T], capArg ...int) S

DeduplicateWith removes the duplicate items from []T slice as a set with Equaller.

func Delete

func Delete[S ~[]T, T comparable](slice S, value T, n int, capArg ...int) S

Delete deletes value from []T slice in n times.

func DeleteAll

func DeleteAll[S ~[]T, T comparable](slice S, value T, capArg ...int) S

DeleteAll deletes value from []T slice in all.

func DeleteAllSelf

func DeleteAllSelf[S ~[]T, T comparable](slice S, value T) S

DeleteAllSelf deletes value from []T slice in all, by modifying given slice directly.

func DeleteAllSelfWith

func DeleteAllSelfWith[S ~[]T, T any](slice S, value T, equaller Equaller[T]) S

DeleteAllSelfWith deletes value from []T slice in all with Equaller, by modifying given slice directly.

func DeleteAllWith

func DeleteAllWith[S ~[]T, T any](slice S, value T, equaller Equaller[T], capArg ...int) S

DeleteAllWith deletes value from []T slice in all with Equaller.

func DeleteSelf

func DeleteSelf[S ~[]T, T comparable](slice S, value T, n int) S

DeleteSelf deletes value from []T slice in n times, by modifying given slice directly.

func DeleteSelfWith

func DeleteSelfWith[S ~[]T, T any](slice S, value T, n int, equaller Equaller[T]) S

DeleteSelfWith deletes value from []T slice in n times with Equaller, by modifying given slice directly.

func DeleteWith

func DeleteWith[S ~[]T, T any](slice S, value T, n int, equaller Equaller[T], capArg ...int) S

DeleteWith deletes value from []T slice in n times with Equaller.

func Diff

func Diff[S ~[]T, T comparable](slice1, slice2 S, capArg ...int) S

Diff returns the difference of two []T slices.

func DiffWith

func DiffWith[S ~[]T, T any](slice1, slice2 S, equaller Equaller[T], capArg ...int) S

DiffWith returns the difference of two []T slices with Equaller.

func ElementMatch

func ElementMatch[T comparable](slice1, slice2 []T) bool

ElementMatch checks whether two []T slices equal (ignore the order of the elements, but the number of duplicate elements should match).

func ElementMatchWith

func ElementMatchWith[T1, T2 any](slice1 []T1, slice2 []T2, equaller Equaller2[T1, T2]) bool

ElementMatchWith checks whether two slices equal (ignore the order of the elements, but the number of duplicate elements should match) with Equaller.

func Equal

func Equal[T comparable](slice1, slice2 []T) bool

Equal checks whether two []T slices equal (the same length and all elements equal).

func EqualWith

func EqualWith[T1, T2 any](slice1 []T1, slice2 []T2, equaller Equaller2[T1, T2]) bool

EqualWith checks whether two slices equal (the same length and all elements equal) with Equaller.

func Expand

func Expand[T1, T2 any](slice []T1, f func(T1) []T2, capArg ...int) []T2

Expand maps and expands given slice to another slice using expand function.

func Filter

func Filter[S ~[]T, T any](slice S, f func(T) bool, capArg ...int) S

Filter filters given slice and returns a new slice using given predicate function.

func Foreach

func Foreach[T any](slice []T, f func(T))

Foreach invokes given function for each item of given slice.

func Grow

func Grow[S ~[]T, T any](slice S, n int) S

Grow increases given slice's capacity, if necessary, to guarantee space for another n elements.

func IndexOf

func IndexOf[T comparable](slice []T, value T) int

IndexOf returns the first index of value in the []T slice.

func IndexOfWith

func IndexOfWith[T any](slice []T, value T, equaller Equaller[T]) int

IndexOfWith returns the first index of value in the []T slice with Equaller.

func Insert

func Insert[S ~[]T, T any](slice S, index int, values ...T) S

Insert inserts values into []T slice at index position using a new slice space to store.

func InsertSelf

func InsertSelf[S ~[]T, T any](slice S, index int, values ...T) S

InsertSelf inserts values into []T slice at index position using the space of given slice.

func Intersect

func Intersect[S ~[]T, T comparable](slice1, slice2 S, capArg ...int) S

Intersect returns the intersection of two []T slices.

func IntersectWith

func IntersectWith[S ~[]T, T any](slice1, slice2 S, equaller Equaller[T], capArg ...int) S

IntersectWith returns the intersection of two []T slices with Equaller.

func LastIndexOf

func LastIndexOf[T comparable](slice []T, value T) int

LastIndexOf returns the last index of value in the []T slice.

func LastIndexOfWith

func LastIndexOfWith[T any](slice []T, value T, equaller Equaller[T]) int

LastIndexOfWith returns the last index of value in the []T slice with Equaller.

func Map

func Map[T1, T2 any](slice []T1, f func(T1) T2) []T2

Map maps given slice to another slice using mapper function.

func Reduce

func Reduce[T, U any](slice []T, initial U, f func(U, T) U) U

Reduce reduces given slice to a single value using initial value and left reducer function.

func Repeat

func Repeat[T any](value T, count uint) []T

Repeat generates a []T slice with given value and repeat count.

func Reverse

func Reverse[S ~[]T, T any](slice S) S

Reverse reverses the []T slice and returns the result.

func ReverseSelf

func ReverseSelf[T any](slice []T)

ReverseSelf reverses the []T slice, by modifying given slice directly.

func Shuffle

func Shuffle[S ~[]T, T any](slice S) S

Shuffle shuffles the []T slice and returns the result.

func ShuffleSelf

func ShuffleSelf[T any](slice []T)

ShuffleSelf shuffles the []T slice, by modifying given slice directly.

func Sort

func Sort[S ~[]T, T xsugar.Ordered](slice S) S

Sort sorts the []T slice and returns the result.

func SortSelf

func SortSelf[T xsugar.Ordered](slice []T)

SortSelf sorts the []T slice, by modifying given slice directly.

func SortSelfWith

func SortSelfWith[T any](slice []T, less Lesser[T])

SortSelfWith sorts the []T slice with less function, by modifying given slice directly.

func SortWith

func SortWith[S ~[]T, T any](slice S, less Lesser[T]) S

SortWith sorts the []T slice with less function and returns the result.

func StableSort

func StableSort[S ~[]T, T xsugar.Ordered](slice S) S

StableSort sorts the []T slice in stable and returns the result.

func StableSortSelf

func StableSortSelf[T xsugar.Ordered](slice []T)

StableSortSelf sorts the []T slice in stable, by modifying given slice directly.

func StableSortSelfWith

func StableSortSelfWith[T any](slice []T, less Lesser[T])

StableSortSelfWith sorts the []T slice in stable with less function, by modifying given slice directly.

func StableSortWith

func StableSortWith[S ~[]T, T any](slice S, less Lesser[T]) S

StableSortWith sorts the []T slice in stable with less function and returns the result.

func Union

func Union[S ~[]T, T comparable](slice1, slice2 S, capArg ...int) S

Union returns the union of two []T slices.

func UnionWith

func UnionWith[S ~[]T, T any](slice1, slice2 S, equaller Equaller[T], capArg ...int) S

UnionWith returns the union of two []T slices with Equaller.

func Unzip

func Unzip[T1, T2 any](slice []xtuple.Tuple[T1, T2]) ([]T1, []T2)

Unzip unzips given tuple slice to two slices.

func Unzip3

func Unzip3[T1, T2, T3 any](slice []xtuple.Triple[T1, T2, T3]) ([]T1, []T2, []T3)

Unzip3 unzips given triple slice to three slices.

func Zip

func Zip[T1, T2 any](slice1 []T1, slice2 []T2) []xtuple.Tuple[T1, T2]

Zip zips given two slices to a tuple slice, its length is the less one of two slices.

func Zip3

func Zip3[T1, T2, T3 any](slice1 []T1, slice2 []T2, slice3 []T3) []xtuple.Triple[T1, T2, T3]

Zip3 zips given three slices to a triple slice, its length is the less one of three slices.

Types

type Equaller

type Equaller[T any] func(i, j T) bool

Equaller represents an equality function for two values, is used in XXXWith methods.

type Equaller2

type Equaller2[T1, T2 any] func(i T1, j T2) bool

Equaller2 represents an equality function for two values in different types, is used in XXXWith methods.

type Lesser

type Lesser[T any] func(i, j T) bool

Lesser represents a less function for sort, see sort.Interface.

Jump to

Keyboard shortcuts

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