slice

package module
v0.0.0-...-2dce04b Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 2 Imported by: 20

Documentation

Overview

Package slice provides utility functions for working with slices in Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsAny

func ContainsAny[T comparable](list []T, values ...T) bool

ContainsAny checks if any of the given values present in the list.

func DeleteAt

func DeleteAt[T any](slice []T, index int) (element T, newSlice []T, ok bool)

DeleteAt removes and returns the element at the specified index. It returns the removed element and the modified slice. The third return value (ok) indicates whether an element was removed.

func GroupBy

func GroupBy[T any, K comparable](list []T, key func(T) K) map[K][]T

GroupBy groups a slice of items by a key function.

func Intersperse

func Intersperse[T any](slice []T, insert T) []T

Intersperse puts an item between each element of a slice, returning a new slice.

func IsSubset

func IsSubset[T comparable](a, b []T) bool

IsSubset checks if all elements of slice a are present in slice b.

func Last

func Last[T any](list []T) (T, bool)

Last returns the last element of a slice and true. If the slice is empty, it returns the zero value and false.

func Map

func Map[E any, F any](seq iter.Seq[E], fn func(e E) F) iter.Seq[F]

Map takes an iterator of type E and a mapping function, and returns an iterator of type F.

func Pop

func Pop[T any](slice []T) (element T, newSlice []T, ok bool)

Pop removes and returns the last element of a slice. It returns the removed element and the modified slice. The third return value (ok) indicates whether an element was removed.

func Shift

func Shift[T any](slice []T) (element T, newSlice []T, ok bool)

Shift removes and returns the first element of a slice. It returns the removed element and the modified slice. The third return value (ok) indicates whether an element was removed.

func Take

func Take[A any](slice []A, n int) []A

Take returns the first n elements of the given slice. If there are not enough elements in the slice, the whole slice is returned.

func Uniq

func Uniq[T comparable](list []T) []T

Uniq returns a new slice with all duplicates removed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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