slices

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 2 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any[T any](ts []T, predicate func(t T) bool) bool

Any returns true if at least one element satisfies predicate

func CastAll added in v0.11.0

func CastAll[SS ~[]S, S any, TS ~[]T, T any](ss SS) TS

CastAll converts the type of all elements of the slice If an element cannot be converted, it will panic

func Clone added in v0.6.5

func Clone[TS ~[]T, T any](source TS) TS

func Contains added in v0.15.0

func Contains[T comparable](ts []T, other T) bool

Contains returns true if the slice contains the given element

func Count

func Count[S any](ss []S, p types.Predicate[S]) int

func DeepClone added in v0.6.5

func DeepClone[SS ~[]S, S types.Cloneable[S]](source SS) SS

func Filter

func Filter[SS ~[]S, S any](ss SS, p types.Predicate[S]) SS

func FilterNonNil

func FilterNonNil[TS ~[]*T, T any](ts TS) TS

FilterNonNil returns all the elements of array that are non nil

func FilterNot

func FilterNot[SS ~[]S, S any](ss SS, p types.Predicate[S]) SS

FilterNot removes (filter out) all elements the satisfies predicate

func Find

func Find[S any](ss []S, p types.Predicate[S]) (S, bool)

func FlatMap

func FlatMap[SS ~[]S, S any, TS ~[]T, T any](ss SS, m types.Mapper[S, TS]) TS

func Has

func Has[T types.Comparable[T]](ts []T, other T) bool

func Has2

func Has2[T comparable](ts []T, other T) bool

Has2 returns true if the slice contains the given element Deprecated: use Contains instead

func HasDuplicates added in v0.17.0

func HasDuplicates[TS ~[]T, T comparable](ts TS) bool

HasDuplicates returns true if the slice contains at least one element duplicated

func Index

func Index[S comparable](ss []S, toFind S) int

func Index2

func Index2[S comparable](ss []S, toFind S) (int, bool)

func IndexBy

func IndexBy[S any](ss []S, p types.Predicate[S]) int

func IndexBy2

func IndexBy2[S any](ss []S, p types.Predicate[S]) (int, bool)

func InsertAt added in v0.19.0

func InsertAt[T any](elements []T, idx int, element T) []T

InsertAt inserts the given element at the given index by shifting all elements after it to the right

func JoinDistinct added in v0.7.0

func JoinDistinct[TS ~[]T, T comparable](es ...TS) TS

func Map

func Map[S any, T any](ss []S, m types.Mapper[S, T]) []T

func MapNonNil

func MapNonNil[S any, T any](ss []S, mapper types.Mapper[S, *T]) []T

MapNonNil apply mapper to all elements of 'ss' and return slice of all non-nil results

func MapWithError added in v0.6.6

func MapWithError[S any, T any](ss []S, m types.MapperWithError[S, T]) ([]T, error)

MapWithError applies mapper to all elements of 'ss' and returns slice of results. If mapper returns error, then it is returned immediately.

func Of

func Of[S any](ss ...S) []S

func Reduce

func Reduce[Value any, Element any](
	initialValue Value,
	elements []Element,
	reducer func(Value, Element) Value,
) Value

func Remove

func Remove[TS ~[]T, T types.Comparable[T]](ts TS, toRemove T) TS

Remove all occurrences of the given element from the slice

func RemoveAt added in v0.19.0

func RemoveAt[T any](elements []T, idx int) []T

RemoveAt removes the element at the given index by shifting all elements after it to the left

Types

This section is empty.

Jump to

Keyboard shortcuts

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