slices

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package slices provides utilities to manipulate slices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone[S ~[]E, E any](s S) S

Clone returns a copy of the slice.

func Contains added in v0.2.0

func Contains[S ~[]T, T comparable](s S, t T) bool

Contains returns true if the slice contains the given element.

func Equal added in v0.3.0

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

Equal returns true if the two slices are equal.

func Filter

func Filter[S ~[]T, T any](s S, f func(T) bool) []T

Filter returns a new slice containing all elements in the slice that satisfy the predicate f.

func FilterAndMap added in v0.4.0

func FilterAndMap[S ~[]T, T any, O any](s S, f func(T) (O, bool)) []O

FilterAndMap returns a new slice containing the results of applying the given function to all elements in the slice that satisfy the predicate f.

func Find

func Find[S ~[]T, T any](s S, f func(T) bool) (t T, ok bool)

Find returns the first element in the slice that satisfies the predicate f.

func GroupBy added in v0.5.0

func GroupBy[S ~[]T, T any, K comparable](s S, f func(T) K) map[K][]T

GroupBy returns a map of slices grouped by the given function.

func Map

func Map[S ~[]T, T any, O any](s S, f func(T) O) []O

Map returns a new slice containing the results of applying the given function

func MapWithError added in v0.4.0

func MapWithError[S ~[]T, T any, O any](s S, f func(T) (O, error)) ([]O, error)

MapWithError returns a new slice containing the results of applying the given function to all elements in the slice that satisfy the predicate f.

func Reverse added in v0.3.0

func Reverse[S ~[]T, T any](s S) []T

Reverse returns a new slice containing the elements of the slice in reverse order.

func Unique added in v0.3.0

func Unique[S ~[]T, T comparable](s S) []T

Unique returns a new slice containing only the unique elements in the slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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