exslices

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: MPL-2.0 Imports: 0 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CastFunc added in v0.6.0

func CastFunc[To, From any](source []From, conv func(From) To) []To

func CastFuncFilter added in v0.8.5

func CastFuncFilter[To, From any](source []From, conv func(From) (To, bool)) []To

func CastToAny added in v0.6.0

func CastToAny[From any](source []From) []any

func CastToString added in v0.6.0

func CastToString[To, From ~string](source []From) []To

func Chunk added in v0.4.2

func Chunk[T any](slice []T, size int) (chunks [][]T)

Chunk splits a slice into chunks of the given size.

From https://github.com/golang/go/issues/53987#issuecomment-1224367139

TODO remove this after slices.Chunk can be used (it'll probably be added in Go 1.23, so it can be used after 1.22 is EOL)

func DeduplicateUnsorted added in v0.7.0

func DeduplicateUnsorted[T comparable](s []T) []T

DeduplicateUnsorted removes duplicates from the given slice without requiring that the input slice is sorted. The order of the output will be the same as the input.

If you don't care about the order of the output, it's recommended to sort the list and then use slices.Compact.

func Diff

func Diff[T comparable](a, b []T) (uniqueToA, uniqueToB []T)

Diff returns the difference between two slices. The slices may contain duplicates and don't need to be sorted. The output will not be sorted, but is guaranteed to not contain any duplicates.

func SortedDiff

func SortedDiff[T any](a, b []T, compare func(a, b T) int) (uniqueToA, uniqueToB []T)

SortedDiff returns the difference between two already-sorted slices, with the help of the given comparison function. The output will be in the same order as the input, which means it'll be sorted.

Types

This section is empty.

Jump to

Keyboard shortcuts

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