gotility provides various utility functions, types, and more.
-
First[T any](data []T) T
- Returns the first element of a slice, or the zero value of type T if len(data) == 0.
-
Last[T any](data []T) T
- Returns the last element of a slice, of the zero value of type T if len(data) == 0.
-
Head[T any](data []T) []T
- Returns all elements of a slice except the last.
-
Tail[T any](data []T) []T
- Returns all elements of a slice except the first.
-
Find[T any](data []T, fn CmpFunc[T]) (T, bool)
- Returns the first element of a slice for which
fn
returns true, along with a boolean representing whether a matching value was found.
- Returns the first element of a slice for which
-
FindValue[T comparable](data []T, val T) (T, bool)
- Returns the first element of a slice which is equal to
val
, along with a boolean representing whether a matching value was found.
- Returns the first element of a slice which is equal to
-
Filter[T any](data []T, fn CmpFunc[T]) []T
- Returns all values in a slice for which
fn
returns true.
- Returns all values in a slice for which
-
FilterValue[T comparable](data []T, val T) []T
- Returns all values in a slice which are equal to
val
.
- Returns all values in a slice which are equal to
-
Contains[T any](data []T, fn CmpFunc[T]) bool
- Returns a boolean representing whether
fn
returns true for any element in the passed slice.
- Returns a boolean representing whether
-
ContainsValue[T comparable](data []T, val T) bool
- Returns a boolean representing whether any element in the passed slice ==
val
.
- Returns a boolean representing whether any element in the passed slice ==
-
ToPointer[T any](val T) *T
- Returns a pointer to
val
.
- Returns a pointer to
-
FromPointer[T any](val *T) T
- Returns the non-pointer value of the passed pointer. If the passed pointer is nil, the zero value for type T is returned instead.
ConcurrentMap[K comparable, V any]
- Generic, concurrency-safe wrapper around the inbuilt
map
type.
- Generic, concurrency-safe wrapper around the inbuilt
NewConcurrentMap[K comparable, V any]
- Returns a new, fully initialized
ConcurrentMap
.
- Returns a new, fully initialized