Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComplexFilter ¶ added in v0.1.1
ComplexFilter applies a filter function on a slice of elements based on the provided filter function. As with Filter, this function modifies the original list in-place.
This function uses indices for optimization reasons.
Parameters:
- slice: The slice of elements to filter.
- fn: The filter function that takes a list of indices and returns a boolean indicating whether to early exit.
Behavior:
- If the provided slice is empty or the filter function is nil, the original slice is cleared and set to nil.
- The filter function is called repeatedly with the current list of indices until it returns true or the list of indices is empty.
- The filtered slice contains only the elements corresponding to the selected indices.
func Filter ¶ added in v0.1.2
Filter applies a predicate function on a slice of elements; keeping only those elements that satisfy the predicate. This function modifies the original list in-place.
Parameters:
- slice: the list of elements to filter.
- p: the predicate function to apply.
Behavior:
- If the list is empty, the predicate is nil, or there is no element that satisfies the predicate, the slice is cleared and set to nil.
func IndicesOf ¶ added in v0.1.2
func IndicesOf[T comparable](slice []T, sep T) []int
IndicesOf returns a slice of indices that specify where the separator occurs in the data.
Parameters:
- slice: The data.
- sep: The separator.
Returns:
- []int: The indices. Nil if no separator is found.
func Reject ¶ added in v0.1.2
Reject applies a predicate function on a slice of elements; keeping only those elements that do not satisfy the predicate. This function modifies the original list in-place.
Parameters:
- slice: the list of elements to filter.
- p: the predicate function to apply.
Returns:
- []T: the list of elements that do not satisfy the predicate.
Behavior:
- If the list is empty or the predicate is nil, returns nil.
func RejectNils ¶
func RejectNils[T any](slice *[]*T)
RejectNils works like Reject but keeps only non-nil elements.
Parameters:
- slice: the list of elements to filter.
Types ¶
type Builder ¶ added in v0.1.1
type Builder[T any] struct { // contains filtered or unexported fields }
Builder is a builder for slices. While this is normally not needed, it can have some uses when making many slices one after the other.
func (*Builder[T]) Append ¶ added in v0.1.1
Append appends an element to the slice being built.
Parameters:
- elem: The element to append.
Returns:
- error: An error if the receiver is nil.