ds

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package ds provides some utilities relating to data structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy added in v0.3.12

func Copy[T any, ST ~[]T](arr ST) ST

func FlatMap

func FlatMap[T any, R any, ST ~[]T, SR ~[]R](arr ST, iteratee func(T) SR) SR

func FlatMapError

func FlatMapError[T any, R any, ST ~[]T, SR ~[]R](arr ST, iteratee func(T) (SR, error)) (SR, error)

func Limit

func Limit[T any, ST ~[]T](arr ST, limit int) ST

Limit limits array to given limit length, if the slice is larger than the given limit.

func Map

func Map[T any, R any, ST ~[]T](arr ST, iteratee func(T) R) []R

func MapError

func MapError[T any, R any, ST ~[]T](arr ST, iteratee func(T) (R, error)) ([]R, error)

func MergeMap added in v0.7.0

func MergeMap[K comparable, V any, M ~map[K]V](m1, m2 M) M

func SortAsc

func SortAsc[E any, K constraints.Ordered](key func(e E) K) func(e1, e2 E) int

func SortCompose

func SortCompose[E any](comparators ...func(e1, e2 E) int) func(e1, e2 E) int

func SortDesc

func SortDesc[E any, K constraints.Ordered](key func(e E) K) func(e1, e2 E) int

func Uniq added in v0.7.1

func Uniq[E comparable, S ~[]E](sorted S) S

Uniq compresses all successive duplicate elements in sorted slice, like unix command 'uniq'.

Types

type SyncMap added in v0.3.4

type SyncMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

SyncMap is a simple wrapper around sync.Map. https://www.reddit.com/r/golang/comments/twucb0/comment/j4x7xbx/

func (*SyncMap[K, V]) Copy added in v0.4.0

func (m *SyncMap[K, V]) Copy() map[K]V

func (*SyncMap[K, V]) Delete added in v0.3.4

func (m *SyncMap[K, V]) Delete(key K)

func (*SyncMap[K, V]) Load added in v0.3.4

func (m *SyncMap[K, V]) Load(key K) (value V, ok bool)

func (*SyncMap[K, V]) LoadAndDelete added in v0.3.4

func (m *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)

func (*SyncMap[K, V]) LoadOrStore added in v0.3.4

func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

func (*SyncMap[K, V]) Range added in v0.3.4

func (m *SyncMap[K, V]) Range(f func(key K, value V) bool)

func (*SyncMap[K, V]) Store added in v0.3.4

func (m *SyncMap[K, V]) Store(key K, value V)

Jump to

Keyboard shortcuts

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