mutable

package
v1.51.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: MIT Imports: 1 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter added in v1.50.0

func Filter[T any, Slice ~[]T](collection Slice, predicate func(item T) bool) Slice

Filter is a generic function that modifies the input slice in-place to contain only the elements that satisfy the provided predicate function. The predicate function takes an element of the slice and its index, and should return true for elements that should be kept and false for elements that should be removed. The function returns the modified slice, which may be shorter than the original if some elements were removed. Note that the order of elements in the original slice is preserved in the output.

func FilterI added in v1.50.0

func FilterI[T any, Slice ~[]T](collection Slice, predicate func(item T, index int) bool) Slice

FilterI is a generic function that modifies the input slice in-place to contain only the elements that satisfy the provided predicate function. The predicate function takes an element of the slice and its index, and should return true for elements that should be kept and false for elements that should be removed. The function returns the modified slice, which may be shorter than the original if some elements were removed. Note that the order of elements in the original slice is preserved in the output.

func Map added in v1.50.0

func Map[T any, Slice ~[]T](collection Slice, fn func(item T) T)

Map is a generic function that modifies the input slice in-place to contain the result of applying the provided function to each element of the slice. The function returns the modified slice, which has the same length as the original.

func MapI added in v1.50.0

func MapI[T any, Slice ~[]T](collection Slice, fn func(item T, index int) T)

MapI is a generic function that modifies the input slice in-place to contain the result of applying the provided function to each element of the slice. The function returns the modified slice, which has the same length as the original.

func Reverse

func Reverse[T any, Slice ~[]T](collection Slice)

Reverse reverses array so that the first element becomes the last, the second element becomes the second to last, and so on. Play: https://go.dev/play/p/O-M5pmCRgzV

func Shuffle

func Shuffle[T any, Slice ~[]T](collection Slice)

Shuffle returns an array of shuffled values. Uses the Fisher-Yates shuffle algorithm. Play: https://go.dev/play/p/2xb3WdLjeSJ

Types

This section is empty.

Jump to

Keyboard shortcuts

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