Documentation
¶
Overview ¶
Package sliceutils defines utilities for working with slices; before using this package, consider using the package "slices".
Index ¶
- func AnySliceToSlice[T any](value []any) maybe.Maybe[[]T]
- func AnyToAnySlice(value any) maybe.Maybe[[]any]
- func AssertContains[T comparable](target []T, value T) error
- func CollectErrors[T any](root error, elements ...result.Result[T]) error
- func ContainsAll[T comparable](target []T, values []T) bool
- func Detect[T any](detect filters.Filter[T], values []T) result.Result[maybe.Maybe[T]]
- func DetectNoError[T any](detect filters.FilterNoError[T], values []T) maybe.Maybe[T]
- func DetectNoErrorResult[T any](filter filters.FilterNoError[T], values result.Result[[]T]) result.Result[maybe.Maybe[T]]
- func DetectResult[T any](filter filters.Filter[T], source result.Result[[]T]) result.Result[maybe.Maybe[T]]
- func Disjoint[T comparable](left []T, right []T) result.Result[[]T]
- func Duplicate[T any](src []T) []T
- func FirstError[T any](elements ...result.Result[T]) error
- func Fold[T, S any](folder folders.Folder[T, S], initial T, source []S) result.Result[T]
- func FoldNoError[T, S any](folder folders.FolderNoError[T, S], initial T, source []S) T
- func FoldNoErrorResult[T, S any](folder folders.FolderNoError[T, S], initial T, source result.Result[[]S]) result.Result[T]
- func FoldResult[T, S any](folder folders.Folder[T, S], initial T, source result.Result[[]S]) result.Result[T]
- func Head[T any](source []T) maybe.Maybe[T]
- func Intersection[T comparable](left []T, right []T) result.Result[[]T]
- func LenAll[T any](values ...[]T) int
- func Map[T, S any](mapper result.FlatMapper[S, T], source []S) result.Result[[]T]
- func MapNoError[T, S any](mapper MapperNoError[S, T], source []S) []T
- func MapNoErrorResult[T, S any](mapper MapperNoError[S, T], source result.Result[[]S]) result.Result[[]T]
- func MapResult[T, S any](mapper result.FlatMapper[S, T], source result.Result[[]S]) result.Result[[]T]
- func Prepend[T any](target []T, values ...T) []T
- func Remove[T comparable](target []T, values ...T) []T
- func Reverse[T any](values []T) []T
- func Select[T any](filter filters.Filter[T], source []T) result.Result[[]T]
- func SelectNoError[T any](filter filters.FilterNoError[T], source []T) []T
- func SelectNoErrorResult[T any](filter filters.FilterNoError[T], source result.Result[[]T]) result.Result[[]T]
- func SelectResult[T any](filter filters.Filter[T], source result.Result[[]T]) result.Result[[]T]
- func SelectUsingSubsetInterfaceFilter[T any, S any](filter filters.Filter[S], source []T) result.Result[[]T]
- func SelectUsingSubsetInterfaceFilterNoError[T any, S any](filter filters.FilterNoError[S], source []T) result.Result[[]T]
- func Tail[T any](source []T) maybe.Maybe[[]T]
- func ToSlice[T any](values ...T) []T
- func Union[T comparable](values ...[]T) result.Result[[]T]
- func UniqueUnion[T comparable](values ...[]T) result.Result[[]T]
- type MapperNoError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnySliceToSlice ¶
AnySliceToSlice returns a typed slice from the specified 'any' slice; additionally, returns false when the specified 'any' slice cannot be converted into a typed slice, otherwise true.
func AnyToAnySlice ¶
AnyToAnySlice returns an 'any' slice from the specified 'any' value; additionally, returns false when the specified 'any' value cannot be converted to an 'any' slice, otherwise true.
func AssertContains ¶
func AssertContains[T comparable](target []T, value T) error
AssertContains returns an error if the given target slice of values does not contain the give value, otherwise it returns nil. The returned error describes the missing values. For a non-asserting contains function, use slices.Contains from the Go standard library.
func CollectErrors ¶
CollectErrors returns a multi-error for all errors in the given slice of result.Result.
func ContainsAll ¶ added in v0.2.0
func ContainsAll[T comparable](target []T, values []T) bool
ContainsAll returns true if the given target slice of values contains all the given values, otherwise it returns false.
func Detect ¶
Detect returns the first value found in the given slice of values that matches the given filter. Returns a maybe.Nothing if no value is found. Returns a result.Error if the filter fails.
func DetectNoError ¶
func DetectNoError[T any]( detect filters.FilterNoError[T], values []T, ) maybe.Maybe[T]
DetectNoError returns the first value found in the given slice of values that matches the given filter. Returns a maybe.Nothing if no value is found.
func DetectNoErrorResult ¶
func DetectNoErrorResult[T any]( filter filters.FilterNoError[T], values result.Result[[]T], ) result.Result[maybe.Maybe[T]]
DetectNoErrorResult calls DetectNoError on the slice encapsulated in the given result. If the given result encapsulates an error, that error is returned in a result of the return type.
func DetectResult ¶
func DetectResult[T any]( filter filters.Filter[T], source result.Result[[]T], ) result.Result[maybe.Maybe[T]]
DetectResult returns the first value found in the given slice of values that matches the given filter. Returns a maybe.Nothing if no value is found. Returns a result.Error if the filter fails.
func Disjoint ¶
func Disjoint[T comparable](left []T, right []T) result.Result[[]T]
Disjoint returns the disjoint set of the given two slices; never nil.
func Duplicate ¶ added in v0.2.0
func Duplicate[T any](src []T) []T
Duplicate returns a newly allocated copy of the given slice.
func FirstError ¶
FirstError returns the first error, if any, in the given slice of result.Result.
func Fold ¶
Fold passes the first element of the given slice and the given initial value to the given folder. The next element and the value in the result returned from the last call to the given folder is passed to the folder until all elements have been passed or an error is returned from the folder.
func FoldNoError ¶
func FoldNoError[T, S any]( folder folders.FolderNoError[T, S], initial T, source []S, ) T
FoldNoError passes the first element of the given slice and the given initial value to the given folder. The next element and the result of the last call to the given folder is passed to the folder until all elements have been passed.
func FoldNoErrorResult ¶
func FoldNoErrorResult[T, S any]( folder folders.FolderNoError[T, S], initial T, source result.Result[[]S], ) result.Result[T]
FoldNoErrorResult calls Fold on the slice encapsulated in the given result. If the given result encapsulates an error, that error is returned in a result of the return type.
func FoldResult ¶
func FoldResult[T, S any]( folder folders.Folder[T, S], initial T, source result.Result[[]S], ) result.Result[T]
FoldResult calls Fold on the slice encapsulated in the given result. If the given result encapsulates an error, that error is returned in a result of the return type.
func Intersection ¶
func Intersection[T comparable](left []T, right []T) result.Result[[]T]
Intersection returns the intersection of the given two slices; never nil.
func Map ¶
func Map[T, S any]( mapper result.FlatMapper[S, T], source []S, ) result.Result[[]T]
Map the given source slice, using the given mapper, into a result of a new slice. Returns a result of the new slice containing the mapped values, never nil.
func MapNoError ¶
func MapNoError[T, S any]( mapper MapperNoError[S, T], source []S, ) []T
MapNoError the given source slice, using the given mapper, into a new slice. Returns the new slice containing the mapped values, never nil.
func MapNoErrorResult ¶
func MapNoErrorResult[T, S any]( mapper MapperNoError[S, T], source result.Result[[]S], ) result.Result[[]T]
MapNoErrorResult calls MapNoError on the slice encapsulated in the given result. If the given result encapsulates an error, that error is returned in a result of the return type.
func MapResult ¶
func MapResult[T, S any]( mapper result.FlatMapper[S, T], source result.Result[[]S], ) result.Result[[]T]
MapResult calls Map on the slice encapsulated in the given result. If the given result encapsulates an error, that error is returned in a result of the return type.
func Prepend ¶
func Prepend[T any](target []T, values ...T) []T
Prepend the given values on the target. Returns a new slice, never nil.
func Remove ¶
func Remove[T comparable](target []T, values ...T) []T
Remove from the given slice the given value; returns a new slice, never nil.
func Reverse ¶
func Reverse[T any](values []T) []T
Reverse the given slice. Returns a new slice; never nil.
func Select ¶
Select returns a slice the values containing the values from the given slice that match the given filter; never nil.
func SelectNoError ¶
func SelectNoError[T any]( filter filters.FilterNoError[T], source []T, ) []T
SelectNoError returns a slice the values containing the values from the given slice that match the given filter; never nil.
func SelectNoErrorResult ¶
func SelectNoErrorResult[T any]( filter filters.FilterNoError[T], source result.Result[[]T], ) result.Result[[]T]
SelectNoErrorResult returns a slice the values containing the values from the given slice that match the given filter; never nil.
func SelectResult ¶
SelectResult returns a slice the values containing the values from the given slice that match the given filter; never nil.
func SelectUsingSubsetInterfaceFilter ¶
func SelectUsingSubsetInterfaceFilter[T any, S any](filter filters.Filter[S], source []T) result.Result[[]T]
SelectUsingSubsetInterfaceFilter mirrors Select, with support for a filter function that acts against an interface of the type to be filtered. If the type to be filtered is the interface itself, then just use Select.
func SelectUsingSubsetInterfaceFilterNoError ¶
func SelectUsingSubsetInterfaceFilterNoError[T any, S any]( filter filters.FilterNoError[S], source []T, ) result.Result[[]T]
SelectUsingSubsetInterfaceFilterNoError mirrors Select, with support for a filter function that acts against an interface of the type to be filtered. If the type to be filtered is the interface itself, then just use Select.
func ToSlice ¶
func ToSlice[T any](values ...T) []T
ToSlice returns the given variadic argument list as a slice.
func Union ¶
func Union[T comparable](values ...[]T) result.Result[[]T]
Union returns a slice containing the union of the given slices; never nil.
func UniqueUnion ¶
func UniqueUnion[T comparable](values ...[]T) result.Result[[]T]
UniqueUnion returns a slice containing the union of the unique elements of the given slices; never nil.
Types ¶
type MapperNoError ¶
type MapperNoError[T, R any] func( T, ) R
MapperNoError defines a function with one argument of any type that returns a single value.