slicesx

package
v1.0.0-beta.227 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsFilterIteratee

func AsFilterIteratee[T any](f func(T) bool) func(T, int) bool

func EmptyAsNil

func EmptyAsNil[T any](s []T) []T

EmptyAsNil returns nil if the slice is empty otherwise the slice is returned. This is useful when in tests we are checking struct equality, as we don't need to care about the slice being zero length or nil.

func ForEachUntilWithErr

func ForEachUntilWithErr[T any](s []T, f func(T, int) (breaks bool, err error)) error

func Last

func Last[T any](s []T, f func(T) bool) (*T, int, bool)

Returns the last element in the slice where the predicate returns true

func Map

func Map[T any, S any](s []T, f func(T) S) []S

Map maps elements of a slice from T to M, returning a new slice.

func MapWithErr

func MapWithErr[T any, S any](s []T, f func(T) (S, error)) ([]S, error)

MapWithErr maps elements of a slice from T to M, returning a new slice and a joined error if there are any. If an error is returned from the mapping function, a nil array and the error is returned.

func SliceToPtrSlice

func SliceToPtrSlice[T any](s []T) []*T

func UniqueGroupBy

func UniqueGroupBy[T any, U comparable, Slice ~[]T](collection Slice, iteratee func(item T) U) (map[U]T, bool)

Types

type Diff

type Diff[T comparable, S ~[]T] struct {
	// contains filtered or unexported fields
}

func NewDiff

func NewDiff[T comparable, S ~[]T](base, new S) *Diff[T, S]

func (Diff[T, S]) Additions

func (d Diff[T, S]) Additions() S

func (Diff[T, S]) Changed

func (d Diff[T, S]) Changed() S

func (Diff[T, S]) Has

func (d Diff[T, S]) Has(item T) bool

func (Diff[T, S]) HasChanged

func (d Diff[T, S]) HasChanged() bool

func (Diff[T, S]) InAdditions

func (d Diff[T, S]) InAdditions(item T) bool

func (Diff[T, S]) InRemovals

func (d Diff[T, S]) InRemovals(item T) bool

func (Diff[T, S]) Removals

func (d Diff[T, S]) Removals() S

Jump to

Keyboard shortcuts

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