Documentation
¶
Index ¶
- func All[T any](values []T, predicate func(T) bool) bool
- func Any[T any](values []T, predicate func(T) bool) bool
- func Contains[T comparable](values []T, value T) bool
- func Difference[T comparable](slice, other []T) []T
- func Drop[T any](values []T, index int) (rest []T)
- func Each[T any](values []T, action func(T)) []T
- func Filter[T any](values []T, predicate func(T) bool) (res []T)
- func Find[T any](values []T, predicate func(T) bool) (res T, err error)
- func GroupBy[K comparable, V any](values []V, f func(V) K) map[K][]V
- func Intersection[T comparable](a, b []T) (res []T)
- func Last[T any](values []T) T
- func Map[T, P any](values []T, transform func(T) P) []P
- func Max[T constraints.Ordered](values []T) T
- func Min[T constraints.Ordered](values []T) T
- func Partition[T any](values []T, predicate func(T) bool) ([]T, []T)
- func Reduce[T, P any](values []T, reduction func(T, P) P, acc P) P
- func Sum[T constraints.Ordered](values []T) (sum T)
- func Ternary[T any](condition bool, pos, neg T) T
- func Unique[T comparable](values []T) (uniques []T)
- type Err
- type Ok
- type Pipe
- func (c Pipe[T]) All(predicate func(T) bool) bool
- func (c Pipe[T]) Any(predicate func(T) bool) bool
- func (c Pipe[T]) Contains(value T) bool
- func (c Pipe[T]) Each(action func(T))
- func (c Pipe[T]) Filter(predicate func(n T) bool) Pipe[T]
- func (c Pipe[T]) Find(predicate func(n T) bool) (T, error)
- func (c Pipe[T]) Map(transform func(n T) T) Pipe[T]
- func (c Pipe[T]) Max() T
- func (c Pipe[T]) Min() T
- func (c Pipe[T]) Partition(predicate func(T) bool) ([]T, []T)
- func (c Pipe[T]) Reduce(reducer func(n, acc T) T, acc T) T
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
All returns true if all the values in the slice pass the predicate truth test. Short-circuits and stops traversing the slice if a false element is found.
func Any ¶
Any returns true if any of the values in the slice pass the predicate truth test. Short-circuits and stops traversing the slice if a true element is found.
func Contains ¶
func Contains[T comparable](values []T, value T) bool
Contains returns true if the value is present in the slice
func Difference ¶
func Difference[T comparable](slice, other []T) []T
Difference Returns a copy of the array with all instances of the values that are not present in the other array.
func Drop ¶
Drop returns the rest of the elements in a slice. Pass an index to return the values of the slice from that index onward.
func Each ¶
func Each[T any](values []T, action func(T)) []T
Each iterates over a slice of elements, yielding each in turn to an action function. Returns the slice for piping.
func Filter ¶
Filter looks through each value in the slice, returning a slice of all the values that pass a truth test (predicate).
func Find ¶
Find looks through each value in the slice, returning the first one that passes a truth test (predicate), or the default value for the type and an error if no value passes the test. The function returns as soon as it finds an acceptable element, and doesn't traverse the entire slice.
func GroupBy ¶
func GroupBy[K comparable, V any](values []V, f func(V) K) map[K][]V
GroupBy splits a slice into a map[K][]V grouped by the result of the iterator function.
func Intersection ¶
func Intersection[T comparable](a, b []T) (res []T)
Intersection computes the list of values that are the intersection of all the slices. Each value in the result is present in each of the slices.
func Map ¶
func Map[T, P any](values []T, transform func(T) P) []P
Map produces a new slice of values by mapping each value in the slice through a transform function.
func Max ¶
func Max[T constraints.Ordered](values []T) T
Max returns the maximum value in the slice. This function can currently only compare numbers reliably. This function uses operator <.
func Min ¶
func Min[T constraints.Ordered](values []T) T
Min returns the minimum value in the slice. This function can currently only compare numbers reliably. This function uses operator <.
func Partition ¶
Partition splits the slice into two slices: one whose elements all satisfy predicate and one whose elements all do not satisfy predicate.
func Reduce ¶
func Reduce[T, P any](values []T, reduction func(T, P) P, acc P) P
Reduce combine a list of values into a single value. acc is the initial state, and each successive step of it should be returned by the reduction function.
func Unique ¶
func Unique[T comparable](values []T) (uniques []T)
Types ¶
type Pipe ¶
type Pipe[T constraints.Ordered] struct { Value []T }
func NewPipe ¶
func NewPipe[T constraints.Ordered](value []T) Pipe[T]
NewPipe starts a Pipe. All future method calls will return Pipe structs. When you've finished the computation, call Value to retrieve the final value.
Methods not returning a slice such as Reduce, All, Any, will break the Pipe and return Value instantly.
func (Pipe[T]) All ¶
All returns true if all the values in the slice pass the predicate truth test. Short-circuits and stops traversing the slice if a false element is found. Breaks the Pipe.
func (Pipe[T]) Any ¶
Any returns true if any of the values in the slice pass the predicate truth test. Short-circuits and stops traversing the slice if a true element is found. Breaks the Pipe.
func (Pipe[T]) Contains ¶
Contains returns true if the value is present in the slice and breaks the Pipe.
func (Pipe[T]) Each ¶
func (c Pipe[T]) Each(action func(T))
Each iterates over a slice of elements, yielding each in turn to an action function. Breaks the Pipe.
func (Pipe[T]) Filter ¶
Filter looks through each value in the slice, returning a slice of all the values that pass a truth test (predicate).
func (Pipe[T]) Find ¶
Find looks through each value in the slice, returning the first one that passes a truth test (predicate), or the default value for the type and an error if no value passes the test. The function returns as soon as it finds an acceptable element, and doesn't traverse the entire slice. Breaks the Pipe.
func (Pipe[T]) Map ¶
Map produces a new slice of values by mapping each value in the slice through a transform function.
TODO: Move from T to P.
func (Pipe[T]) Max ¶
func (c Pipe[T]) Max() T
Max returns the maximum value in the slice. This function can currently only compare numbers reliably. This function uses operator <. Breaks the Pipe.
func (Pipe[T]) Min ¶
func (c Pipe[T]) Min() T
Min returns the minimum value in the slice. This function can currently only compare numbers reliably. This function uses operator <. Breaks the Pipe.
