basics

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package basics provides utility functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal[T comparable](l, r []T) bool

Equal compares two slices of the same type for equality

func EqualFunc

func EqualFunc[T any](l, r []T, cmp func(T, T) bool) bool

EqualFunc compares two slices of the same type using a custom comparison

func Filter

func Filter[T any](s []T, f func(T) bool) []T

Filter returns a new slice containing only the elements that satisfy the provided predicate function

func Find

func Find[T any](s []T, f func(T) bool) (T, bool)

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

func IndexedMap

func IndexedMap[In, Out any](s []In, fn func(elem In, idx int) Out) []Out

IndexedMap returns a new slice by applying the provided mapping function to each element of the input slice, passing the index of each element as a second argument

func Map

func Map[In, Out any](s []In, f func(In) Out) []Out

Map returns a new slice by applying the provided mapping function to each element of the input slice

func MapKeys

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

MapKeys returns the keys of the provided map as a slice

func MapValues

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

MapValues returns the values of the provided map as a slice

func SortedFunc

func SortedFunc[T any](s []T, cmp func(l, r T) int) []T

SortedFunc returns a sorted copy of the slice using the provided comparison function

func SortedKeys

func SortedKeys[K cmp.Ordered, V any](m map[K]V) []K

SortedKeys returns the keys of the provided map as a sorted slice

func SortedKeysFunc

func SortedKeysFunc[K comparable, V any](m map[K]V, cmp func(l, r K) int) []K

SortedKeysFunc returns the keys of the provided map as a sorted slice using the provided comparison function

func SortedMap

func SortedMap[In any, Out cmp.Ordered](s []In, f func(In) Out) []Out

SortedMap returns a sorted copy of the slice after applying the provided mapping function to each element

Types

This section is empty.

Jump to

Keyboard shortcuts

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