slice

package
v1.3.15 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 0 Imported by: 1

README

slice

Go Report Card Documentation license

Simplifies slice operations in Go, with generics!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[T comparable](slice []T, e T) bool

Contains returns true if a slice contains an element

func CountWhere added in v0.1.20

func CountWhere[T any](slice []T, condition func(T) bool) int

CountWhere returns the number of elements in a slice that satisfy a given condition.

func Diff added in v1.3.0

func Diff[T comparable](original, changed []T) (newItems, removedItems []T)

Diff finds the difference between two slices, `original` and `changed`. It returns two new slices for the changes. The first slice contains new items that are in `changed` but not in `original`, and the second slice contains removed items that are in `original` but not in `changed`.

func Map added in v0.1.2

func Map[T any, K comparable, V any](slice []T, fn func(T) (K, V)) map[K]V

Map takes a slice of a given type and a function to extract a map key and value from slice elements, returns a new map with those key-value pairs. Note that if multiple elements in the slice return the same key, the element that appears last in the slice will be the (only) element that maps to the key.

func Transform

func Transform[T any, V any](slice []T, fn func(T) V) []V

Transform takes a slice of a given type, and a function to perform on each element to transform it into a different type

Types

This section is empty.

Jump to

Keyboard shortcuts

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