slices

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2023 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package slices contains a utility functions to work with slices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clip deprecated added in v0.4.5

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

Clip removes unused capacity from the slice, returning s[:len(s):len(s)].

Deprecated: Use slices.Clip instead.

func Clone deprecated added in v0.4.5

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

Clone returns a copy of the slice. The elements are copied using assignment, so this is a shallow clone.

Deprecated: Use slices.Clone instead.

func Contains deprecated

func Contains[T any](s []T, fn func(T) bool) bool

Contains reports whether v is present in s.

Deprecated: Use slices.ContainsFunc instead.

func Copy deprecated

func Copy[S ~[]V, V any](s S, n int) S

Copy copies first n elements. If n is greater than the length of the slice, it will copy the whole slice.

Deprecated: Use xslices.CopyN instead.

func Filter deprecated

func Filter[S ~[]T, T any](slc S, fn func(T) bool) S

Filter returns a slice containing all the elements of s that satisfy fn.

Deprecated: Use xslices.Filter instead.

func FilterInPlace deprecated

func FilterInPlace[S ~[]V, V any](slc S, fn func(V) bool) S

FilterInPlace filters the slice in place.

Deprecated: Use xslices.FilterInPlace instead.

func FlatMap deprecated

func FlatMap[T, R any](slc []T, fn func(T) []R) []R

FlatMap applies the function fn to each element of the slice and returns a new slice with the results. It flattens the result of fn into the result slice.

Deprecated: Use xslices.FlatMap instead.

func Grow deprecated added in v0.4.5

func Grow[S ~[]E, E any](s S, n int) S

Grow increases the slice's capacity, if necessary, to guarantee space for another n elements. After Grow(n), at least n elements can be appended to the slice without another allocation. If n is negative or too large to allocate the memory, Grow panics.

Deprecated: Use slices.Grow instead.

func IndexFunc deprecated

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

IndexFunc returns the first index satisfying fn(slc[i]), or -1 if none do.

Deprecated: Use slices.IndexFunc instead.

func Map deprecated

func Map[T, R any](slc []T, fn func(T) R) []R

Map applies the function fn to each element of the slice and returns a new slice with the results.

Deprecated: Use xslices.Map instead.

func ToMap deprecated

func ToMap[T any, K comparable, V any](slc []T, fn func(T) (K, V)) map[K]V

ToMap converts a slice to a map.

Deprecated: Use xslices.ToMap instead.

func ToSet deprecated

func ToSet[T comparable](slc []T) map[T]struct{}

ToSet converts a slice to a set.

Deprecated: Use xslices.ToSet instead.

func ToSetFunc deprecated

func ToSetFunc[T any, K comparable](slc []T, fn func(T) K) map[K]struct{}

ToSetFunc converts a slice to a set using the function fn.

Deprecated: Use xslices.ToSetFunc instead.

Types

This section is empty.

Jump to

Keyboard shortcuts

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