Documentation ¶
Overview ¶
Package gog provides utilities for working with Go generics.
Index ¶
- func Dedupe[T comparable](slice []T) []T
- func Map[S, T any](slice []S, fn func(S) T) []T
- func Partition[S any, K comparable](slice []S, fn func(S) K) map[K][]S
- func PtrOf[T any](v T) *T
- func Reduce[S, T any](slice []S, initialValue T, fn func(accum T, value S) T) T
- func Select[S any](slice []S, fn func(S) bool) []S
- func ValueOf[T any](v *T, defaultValue T) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dedupe ¶ added in v0.2.0
func Dedupe[T comparable](slice []T) []T
Dedupe returns a new slice that contains only distinct elements from the original slice.
func Map ¶
func Map[S, T any](slice []S, fn func(S) T) []T
Map can be used to transform one slice into another by providing a function to do the mapping.
func Partition ¶
func Partition[S any, K comparable](slice []S, fn func(S) K) map[K][]S
Partition splits the specified slice into groups, each having a key according to the specified function.
func Reduce ¶
func Reduce[S, T any](slice []S, initialValue T, fn func(accum T, value S) T) T
Reduce compacts a slice into a single value. The provided function is used to perform the reduction starting with the initialValue.
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
Package ds provides various data structure implementations with generics.
|
Package ds provides various data structure implementations with generics. |
Package filter adds helper functions for performing filtering over a data set.
|
Package filter adds helper functions for performing filtering over a data set. |
Package opt provides utilities for optional types.
|
Package opt provides utilities for optional types. |
Click to show internal directories.
Click to hide internal directories.