slices

package
v0.7.11 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 3 Imported by: 11

Documentation

Overview

A package to operate on slices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any[T any](fn func(v T) bool, slice ...T) bool

Any checks if any element in a slice satisfies a predicate.

func Append

func Append[T any](slice []T, elements ...T) []T

Append adds elements to a slice.

func Cut

func Cut[T comparable](i, j int, a ...T) []T

Cut removes an element from a slice at a given position.

func Delete

func Delete[T comparable](i int, a ...T) []T

Delete removes an element from a slice by value.

func FailForEach added in v0.7.8

func FailForEach[T any](fn func(v T, i int) error, slice ...T) error

FailForEach applies a function to all elements in a slice and returns an error if the function returns false for any element.

func Filter

func Filter[T any](fn func(v T) bool, slice ...T) []T

Filter removes all elements from a slice that satisfy a predicate.

func Find added in v0.7.6

func Find[T any](fn func(v T) bool, slice ...T) (T, bool)

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

func FindIndex added in v0.7.6

func FindIndex[T any](fn func(v T) bool, slice ...T) (int, bool)

FindIndex returns the index of the first element in a slice that satisfies a predicate.

func First

func First[T any](slice ...T) T

First returns the first element of a slice.

func ForEach added in v0.7.1

func ForEach[T any](fn func(v T, i int), slice ...T)

ForEach applies a function to all elements in a slice.

func GreaterThen added in v0.7.6

func GreaterThen[T any](i int, elements ...T) bool

GreaterThen checks if the first slice is greater than the second slice.

func In

func In[T comparable](val T, slice ...T) bool

In checks if a value is in a slice.

func Index

func Index[T any](fn func(v T) bool, slice ...T) int

Index returns the index of the first element in a slice that satisfies a predicate.

func Insert

func Insert[T comparable](x T, idx int, a ...T) []T

Insert adds an element at a given position in a slice.

func KeyValue added in v0.7.8

func KeyValue[K comparable, V any](m map[K]V) []string

KeyValue returns a string slice of key-value pairs from a map.

func Last

func Last[T any](slice ...T) T

Last returns the last element of a slice.

func Len

func Len[T any](i int, elements ...T) bool

Len returns the length of a slice.

func LessThen added in v0.7.6

func LessThen[T any](i int, elements ...T) bool

LessThen checks if the first slice is less than the second slice.

func Limit

func Limit[T any](limit int, slice ...T) []T

Limit returns a slice with a maximum length of limit.

func Map

func Map[T1 any, T2 any](fn func(v T1) T2, slice ...T1) []T2

Map applies a function to all elements in a slice.

func Pop

func Pop[T comparable](a ...T) (T, []T)

Pop removes an element from the end of a slice.

func Push

func Push[T comparable](x T, a ...T) []T

Push adds an element to the end of a slice.

func Range

func Range(from, to int) []int

Range returns a slice with elements from start to end.

func Reverse

func Reverse[T any](slice []T) []T

Reverse reverses the order of elements in a slice.

func Size

func Size[T any](size int, slice ...T) bool

Size checks if a slice has a specific size.

func Slice

func Slice[T any](slice []any) []T

Slice casts an interface to a slice of a specific type.

func Unique

func Unique[T1 any, T2 comparable](fn func(v T1) T2, slice ...T1) []T1

Unique returns a slice with all duplicate elements removed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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