slicez

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk

func Chunk[T any](s []T, chunkSize int) [][]T

Chunk splits slice s into chunks of size chunkSize, and returns the result.

func ChunkProcess

func ChunkProcess[T any](s []T, chunkSize int, process func([]T) error) error

ChunkProcess splits slice s into chunks of size chunkSize, and calls process on each chunk.

func Contains

func Contains[T comparable](s []T, v T) bool

Contains returns true if v is present in s.

func ContainsFunc added in v0.0.15

func ContainsFunc[T comparable](s []T, fn func(T) bool) bool

ContainsFunc returns true if there is an element in s that satisfies f(s[i]).

func Copy

func Copy[T any](s []T, start, length int) []T

Copy copies length elements from s starting at position start. If length is negative, it will copy all elements from start to the end of s.

func Diff

func Diff[T comparable](dst, s1, s2 []T) []T

Diff compares slices s1 and s2, puts elements from s1 that do not exist in s2 into dst, and returns it.

func DiffInPlaceFirst

func DiffInPlaceFirst[T comparable](s1, s2 []T) []T

DiffInPlaceFirst compares s1 and s2, moves elements from s1 that not in s2 to the front of s1, and returns this portion of s1. Please note that the order of elements in s1 will be altered.

func Equal

func Equal[T comparable](s1, s2 []T) bool

Equal compares slices s1 and s2, and returns true if they are equal. If s1 or s2 is nil, it returns true.

func Filter

func Filter[T any](dst, s []T, predicate func(T) bool) []T

Filter puts elements from s that satisfy predicate into dst, and returns it.

func FilterInPlace

func FilterInPlace[T any](s []T, predicate func(T) bool) []T

FilterInPlace moves elements that satisfy predicate to the front of s, and returns this portion of s. Please note that the order of elements in s will be altered.

func Index

func Index[T comparable](s []T, v T) int

Index returns the index of the first instance of v in s, or -1 if v is not present in s.

func IndexFunc added in v0.0.15

func IndexFunc[T any](s []T, fn func(T) bool) int

IndexFunc returns the first index i satisfying f(s[i]), or -1 if there is no such index.

func Intersect

func Intersect[T comparable](dst, s1, s2 []T) []T

Intersect compares slices s1 and s2, puts elements from s1 that are also present in s2 into dst, and returns it.

func IntersectInPlaceFirst

func IntersectInPlaceFirst[T comparable](s1, s2 []T) []T

IntersectInPlaceFirst compares s1 and s2, moves elements from s1 that are also present in s2 to the front of s1, and returns this portion of s1. Please note that the order of elements in s1 will be altered.

func Unique

func Unique[T comparable](dst, s []T) []T

Unique compares slice s, puts unique elements into dst, and returns it.

func UniqueByKey added in v0.0.15

func UniqueByKey[T any, K comparable](dst, s []T, keyFn func(T) K) []T

UniqueByKey through keyFn get the key of slice s, puts unique elements into dst, and returns it.

func UniqueByKeyInPlace added in v0.0.15

func UniqueByKeyInPlace[T any, K comparable](s []T, keyFn func(T) K) []T

UniqueByKeyInPlace through keyFn get the key of slice s, moves unique elements to the front of s, and returns this portion of s.

func UniqueInPlace

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

UniqueInPlace compares slice s, moves unique elements to the front of s, and returns this portion of s. Please note that the order of elements in s will be altered.

func Values added in v0.0.15

func Values[T, V any](fn func(T) V, ss ...[]T) []V

Values returns a new slice containing the values returned by applying fn to each element of s.

Types

This section is empty.

Jump to

Keyboard shortcuts

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