slices

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Overview

Package slices provides generic slice utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Difference added in v1.1.0

func Difference[S ~[]E, E comparable](a, b S) S

Difference returns all the elements in 'a' that are not in 'b'.

NOTE: The provided slices may contain duplicates but the returned slice will not.

func Filter

func Filter[S ~[]E, E any](s S, p ...func(e E) bool) S

Filter removes all elements in the given slice that do not match the given predicates.

NOTE: Providing no predicates results in a no-op.

func Intersection added in v1.1.0

func Intersection[S ~[]E, E comparable](a, b S) S

Intersection returns all the elements that are in both 'a' and 'b'.

NOTE: The provided slices may contain duplicates but the returned slice will not.

func Map added in v1.2.0

func Map[AS ~[]A, BS ~[]B, A, B any](as AS, fn func(a A) B) BS

Map applies the given function to each element of the provided slice.

func Subset

func Subset[S ~[]E, E comparable](a, b S) bool

Subset returns a boolean indicating whether a, is a subset of b.

NOTE: Returns true if a has zero elements since an empty set is a subset of all sets.

func Sum

func Sum[S ~[]E, E constraints.Ordered](s S) E

Sum returns the summation of the elements in the provided slice.

func Union

func Union[S ~[]E, E comparable](a, b S) S

Union returns all the elements that are in either 'a' or 'b'.

NOTE: The provided slices may contain duplicates but the returned slice will not.

Types

This section is empty.

Jump to

Keyboard shortcuts

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