package exslices
import "go.mau.fi/util/exslices"
Index ¶
- func CastFunc[To, From any](source []From, conv func(From) To) []To
- func CastToAny[From any](source []From) []any
- func CastToString[To, From ~string](source []From) []To
- func Chunk[T any](slice []T, size int) (chunks [][]T)
- func Diff[T comparable](a, b []T) (uniqueToA, uniqueToB []T)
- func SortedDiff[T any](a, b []T, compare func(a, b T) int) (uniqueToA, uniqueToB []T)
Functions ¶
func CastFunc ¶
func CastFunc[To, From any](source []From, conv func(From) To) []To
func CastToAny ¶
func CastToString ¶
func CastToString[To, From ~string](source []From) []To
func Chunk ¶
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 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 ¶
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.
Source Files ¶
cast.go chunk.go diff.go
- Version
- v0.6.0
- Published
- Jul 16, 2024
- Platform
- darwin/amd64
- Last checked
- 3 hours ago –
Tools for package owners.