slices

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 1 Imported by: 5

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 added in v0.1.19

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 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 First added in v0.1.18

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

First returns the first element of a 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 Last

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

Last returns the last element of a 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 Size added in v0.1.8

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