Documentation ¶
Index ¶
- func DeriveFunc[T any](a []T, f func(current, derived T) T) T
- func FilterFunc[T any](a []T, f func(T) bool) []T
- func Max[T constraints.Ordered](a []T) T
- func MaxParams[T constraints.Ordered](a ...T) T
- func Min[T constraints.Ordered](a []T) T
- func MinParams[T constraints.Ordered](a ...T) T
- func Sum[T constraints.Ordered](a []T) T
- func SumParams[T constraints.Ordered](a ...T) T
- func TransformFunc[T, U any](a []T, f func(T) U) []U
- func TransformFuncWithError[T, U any](a []T, f func(T) (U, error)) ([]U, error)
- type Set
- func (s *Set[T]) Add(elements ...T)
- func (s *Set[T]) AddAll(other *Set[T])
- func (s *Set[T]) Contains(elements ...T) bool
- func (s *Set[T]) Elements() []T
- func (s *Set[T]) ForEach(f func(T))
- func (s *Set[T]) IsEmpty() bool
- func (s *Set[T]) KeepOnly(other *Set[T])
- func (s *Set[T]) Remove(elements ...T)
- func (s *Set[T]) Size() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeriveFunc ¶ added in v0.2.0
func DeriveFunc[T any](a []T, f func(current, derived T) T) T
DeriveFunc will scan the array to gain an insight (a derivation) about the array. For example, given an array of ints it can calculate the max or min.
func FilterFunc ¶
FilterFunc returns an array containing only those elements of a for which f returns true
func Max ¶ added in v0.2.0
func Max[T constraints.Ordered](a []T) T
Max will return the max of the ordered elements
func MaxParams ¶ added in v0.2.0
func MaxParams[T constraints.Ordered](a ...T) T
MaxParams will return the max of the ordered elements
func Min ¶ added in v0.2.0
func Min[T constraints.Ordered](a []T) T
Min will return the min of the ordered elements
func MinParams ¶ added in v0.2.0
func MinParams[T constraints.Ordered](a ...T) T
MinParams will return the min of the ordered elements
func Sum ¶ added in v0.2.0
func Sum[T constraints.Ordered](a []T) T
Sum will return the sum of the ordered elements
func SumParams ¶ added in v0.2.0
func SumParams[T constraints.Ordered](a ...T) T
SumParams will return the sum of the ordered elements
func TransformFunc ¶
func TransformFunc[T, U any](a []T, f func(T) U) []U
TransformFunc returns an array containing the result of f for all elements of a
func TransformFuncWithError ¶
TransformFuncWithError returns an array containing the result of f for all elements of a and allows f to return an error. If f returns an error at any point, an empty array and the error are returned.
Types ¶
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set emulates a mathematical set. It is backed by a map but intent is clearer when using named functions instead of map operations. Presence in the map indicates existence in the set. Not thread-safe
func NewSetOf ¶
func NewSetOf[T comparable](elements ...T) *Set[T]
NewSetOf permits a parameterized type
func (*Set[T]) Contains ¶
Contains returns true if and only if all elements are contained in the set
func (*Set[T]) Elements ¶
func (s *Set[T]) Elements() []T
Elements returns all the elements of the set as an array. Order within the array is not guaranteed.
func (*Set[T]) ForEach ¶ added in v0.5.0
func (s *Set[T]) ForEach(f func(T))
ForEach calls function f with each element of the set. The order in which the elements will be called is not guaranteed.