Help us shape the future of Go! Take the 2026 Go Developer Survey

slices

package
v0.8.7 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](arr []T, fn func(T) bool) bool

All checks if all items satisfy the condition function

func Any

func Any[T any](arr []T, fn func(T) bool) bool

Any checks if any item satisfy the condition function

func Contains

func Contains[T comparable](arr []T, pivot T) bool

Contains test if target array contains pivot If T is a pointer, T needs to implement Equal(T) function, otherwise the pointer address If T is not a pointer, T could be either

func Count

func Count[T any](arr []T, fn func(T) bool) int

Count checks how many items satisfy the condition function

func Filter

func Filter[T any](arr []T, fn func(T) bool) []T

Filter functional filter for array items

func Find

func Find[T any](arr []T, fn func(T) bool) *T

Find search the first item with function

func FindInt

func FindInt(slice []int, target int) bool

FindInt return true if target in slice, return false if not.

func FindString

func FindString(slice []string, target string) bool

FindString return true if target in slice, return false if not.

func FindUint

func FindUint(slice []uint, target uint) bool

FindUint return true if target in slice, return false if not.

func Flatten

func Flatten[T any](arr [][]T) []T

Flatten the given arr

func GroupBy

func GroupBy[T any, V comparable](arr []T, fn func(T) V) map[V][]T

GroupBy group by array items with given projection function

func HasString

func HasString(slice []string, str string) bool

func Index

func Index[T any](arr []T, fn func(T) bool) int

Index search the index of array item with function

func IterToArray

func IterToArray[U any, V any, T Iterable[U, V]](iter T) []V

IterToArray convert iterable to list. Next() should be called to get the first item

func Map

func Map[T any, V any](arr []T, fn func(T) V) []V

Map functional conversion for array items

func Reduce

func Reduce[T any, V any](arr []T, reduce func(V, T) V, v V) V

Reduce array

func RemoveString

func RemoveString(slice []string, remove func(item string) bool) []string

RemoveString remove string from slice if function return true.

func Sort

func Sort[T any](arr []T, cmp func(T, T) bool)

Sort given array

Types

type Iterable

type Iterable[T any, V any] interface {
	Next() bool
	Value() V
	*T
}

Iterable .

Jump to

Keyboard shortcuts

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