slicez

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 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 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 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 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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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