Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyFilter ¶
ApplyFilter applies a predicate function on a list of elements; keeping only those elements that satisfy the predicate.
Parameters:
- elems: the list of elements to filter.
- f: the predicate function to apply.
Returns:
- []T: the list of elements that satisfy the predicate.
Behaviors:
- If the list is empty or the predicate is nil, returns nil.
WARNING: This function modifies the original list if there is at least one element that does not satisfy the predicate. Make sure to copy the list before calling this function if you want to keep the original list.
func ApplyReject ¶
ApplyReject applies a predicate function on a list of elements; keeping only those elements that do not satisfy the predicate.
Parameters:
- elems: the list of elements to filter.
- f: the predicate function to apply.
Returns:
- []T: the list of elements that do not satisfy the predicate.
Behaviors:
- If the list is empty or the predicate is nil, returns nil.
WARNING: This function modifies the original list if there is at least one element that satisfies the predicate. Make sure to copy the list before calling this function if you want to keep the original list.
func ComplexFilter ¶ added in v0.1.1
ComplexFilter applies a filter function on a slice of elements based on the provided filter function.
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 list of selected indices and a flag indicating early exit.
Returns:
- []T: The filtered slice of elements.
Behavior:
- If the provided slice is empty or the filter function is nil, returns nil.
- The filter function should return the selected indices and a flag to indicate early exit.
- The filtered slice contains only the elements corresponding to the selected indices.
func RejectNils ¶
func RejectNils[T interface { IsNil() bool }](elems []T) []T
RejectNils removes all nil elements from the slices if they implement the IsNil() method.
IsNil must return false if the element is nil, otherwise true.
Parameters:
- elems: The elements to remove nils from.
Returns:
- []T: The elements without nils. Nil if all the elements are nil or no elements were specified.
Types ¶
type Builder ¶ added in v0.1.1
type Builder[T any] struct { // contains filtered or unexported fields }
Builder is a slice builder.
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.