Documentation
¶
Index ¶
- type SlicesRegistry
- func (sr *SlicesRegistry) Append(args ...any) ([]any, error)
- func (sr *SlicesRegistry) Chunk(size int, list any) ([][]any, error)
- func (sr *SlicesRegistry) Compact(list any) ([]any, error)
- func (sr *SlicesRegistry) Concat(lists ...any) any
- func (sr *SlicesRegistry) First(list any) (any, error)
- func (sr *SlicesRegistry) Flatten(list any) ([]any, error)
- func (sr *SlicesRegistry) FlattenDepth(deep int, list any) ([]any, error)
- func (sr *SlicesRegistry) Has(element any, list any) (bool, error)
- func (sr *SlicesRegistry) Initial(list any) ([]any, error)
- func (sr *SlicesRegistry) Last(list any) (any, error)
- func (sr *SlicesRegistry) LinkHandler(fh sprout.Handler) error
- func (sr *SlicesRegistry) List(values ...any) []any
- func (sr *SlicesRegistry) Prepend(args ...any) ([]any, error)
- func (sr *SlicesRegistry) RegisterAliases(aliasesMap sprout.FunctionAliasMap) error
- func (sr *SlicesRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error
- func (sr *SlicesRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error
- func (sr *SlicesRegistry) Rest(list any) ([]any, error)
- func (sr *SlicesRegistry) Reverse(list any) ([]any, error)
- func (sr *SlicesRegistry) Slice(args ...any) (any, error)
- func (sr *SlicesRegistry) SortAlpha(list any) []string
- func (sr *SlicesRegistry) SplitList(sep string, value string) []string
- func (sr *SlicesRegistry) StrSlice(value any) []string
- func (sr *SlicesRegistry) UID() string
- func (sr *SlicesRegistry) Uniq(list any) ([]any, error)
- func (sr *SlicesRegistry) Until(count int) []int
- func (sr *SlicesRegistry) UntilStep(start, stop, step int) []int
- func (sr *SlicesRegistry) Without(args ...any) ([]any, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SlicesRegistry ¶
type SlicesRegistry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *SlicesRegistry
NewRegistry creates a new instance of your registry with the embedded Handler.
func (*SlicesRegistry) Append ¶
func (sr *SlicesRegistry) Append(args ...any) ([]any, error)
Append appends an element to a slice or array, returning an error if the operation isn't applicable.
Parameters:
list any - the original list to append to. v any - the element to append.
Returns:
[]any - the new list with the element appended. error - protect against undesired behavior due to migration to new signature.
For an example of this function in a Go template, refer to Sprout Documentation: append.
func (*SlicesRegistry) Chunk ¶
func (sr *SlicesRegistry) Chunk(size int, list any) ([][]any, error)
Chunk divides a list into chunks of specified size, returning an error if the list is nil or not a slice/array.
Parameters:
size int - the maximum size of each chunk. list any - the list to chunk.
Returns:
[][]any - a list of chunks. error - error if the list is nil or not a slice/array.
For an example of this function in a Go template, refer to Sprout Documentation: chunk.
func (*SlicesRegistry) Compact ¶
func (sr *SlicesRegistry) Compact(list any) ([]any, error)
Compact removes nil or zero-value elements from a list.
Parameters:
list any - the list to compact.
Returns:
[]any - the list without nil or zero-value elements. error - error if the list is nil or not a slice/array.
For an example of this function in a Go template, refer to Sprout Documentation: compact.
func (*SlicesRegistry) Concat ¶
func (sr *SlicesRegistry) Concat(lists ...any) any
Concat merges multiple lists into a single list.
Parameters:
lists ...any - the lists to concatenate.
Returns:
any - a single concatenated list containing elements from all provided lists.
For an example of this function in a Go template, refer to Sprout Documentation: concat.
func (*SlicesRegistry) First ¶
func (sr *SlicesRegistry) First(list any) (any, error)
First returns the first element of a list.
Parameters:
list any - the list from which to take the first element.
Returns:
any - the first element of the list. error - error if the list is nil, empty, or not a slice/array.
For an example of this function in a Go template, refer to Sprout Documentation: first.
func (*SlicesRegistry) Flatten ¶
func (sr *SlicesRegistry) Flatten(list any) ([]any, error)
Flatten flattens a nested list into a single list of elements.
Parameters:
list any - the list to flatten.
Returns:
[]any - the flattened list. error - error if the list is nil or not a slice/array.
For an example of this function in a Go template, refer to Sprout Documentation: flatten.
func (*SlicesRegistry) FlattenDepth ¶
func (sr *SlicesRegistry) FlattenDepth(deep int, list any) ([]any, error)
FlattenDepth flattens a nested list into a single list of elements up to a specified depth.
Parameters:
deep int - the maximum depth to flatten to; -1 for infinite depth. list any - the list to flatten.
Returns:
[]any - the flattened list. error - error if the list is nil or not a slice/array.
For an example of this function in a Go template, refer to Sprout Documentation: flattenDepth.
func (*SlicesRegistry) Has ¶
func (sr *SlicesRegistry) Has(element any, list any) (bool, error)
Has checks if a specified element is present in a collection and handles type errors.
Parameters:
element any - the element to search for in the collection. list any - the collection in which to search for the element.
Returns:
bool - true if the element is found, otherwise false. error - error if the list is not a type that can be searched (not a slice or array).
For an example of this function in a Go template, refer to Sprout Documentation: has.
func (*SlicesRegistry) Initial ¶
func (sr *SlicesRegistry) Initial(list any) ([]any, error)
Initial returns all elements of a list except the last.
Parameters:
list any - the list to process.
Returns:
[]any - the list without the last element. error - error if the list is nil or not a slice/array.
For an example of this function in a Go template, refer to Sprout Documentation: initial.
func (*SlicesRegistry) Last ¶
func (sr *SlicesRegistry) Last(list any) (any, error)
Last returns the last element of a list.
Parameters:
list any - the list from which to take the last element.
Returns:
any - the last element of the list. error - error if the list is nil, empty, or not a slice/array.
For an example of this function in a Go template, refer to Sprout Documentation: last.
func (*SlicesRegistry) LinkHandler ¶
func (sr *SlicesRegistry) LinkHandler(fh sprout.Handler) error
LinkHandler links the handler to the registry at runtime.
func (*SlicesRegistry) List ¶
func (sr *SlicesRegistry) List(values ...any) []any
List creates a list from the provided elements.
Parameters:
values ...any - the elements to include in the list.
Returns:
[]any - the created list containing the provided elements.
For an example of this function in a Go template, refer to Sprout Documentation: list.
func (*SlicesRegistry) Prepend ¶
func (sr *SlicesRegistry) Prepend(args ...any) ([]any, error)
Prepend prepends an element to a slice or array, returning an error if the operation isn't applicable.
Parameters:
list any - the original list to prepend to. v any - the element to prepend.
Returns:
[]any - the new list with the element prepended. error - protect against undesired behavior due to migration to new signature.
For an example of this function in a Go template, refer to Sprout Documentation: prepend.
func (*SlicesRegistry) RegisterAliases ¶ added in v0.6.0
func (sr *SlicesRegistry) RegisterAliases(aliasesMap sprout.FunctionAliasMap) error
func (*SlicesRegistry) RegisterFunctions ¶
func (sr *SlicesRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error
RegisterFunctions registers all functions of the registry.
func (*SlicesRegistry) RegisterNotices ¶ added in v0.6.0
func (sr *SlicesRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error
func (*SlicesRegistry) Rest ¶
func (sr *SlicesRegistry) Rest(list any) ([]any, error)
Rest returns all elements of a list except the first.
Parameters:
list any - the list to process.
Returns:
[]any - the list without the first element. error - error if the list is nil or not a slice/array.
For an example of this function in a Go template, refer to Sprout Documentation: rest.
func (*SlicesRegistry) Reverse ¶
func (sr *SlicesRegistry) Reverse(list any) ([]any, error)
Reverse returns a new list with the elements in reverse order.
Parameters:
list any - the list to reverse.
Returns:
[]any - the list in reverse order. error - error if the list is nil or not a slice/array.
For an example of this function in a Go template, refer to Sprout Documentation: reverse.
func (*SlicesRegistry) Slice ¶
func (sr *SlicesRegistry) Slice(args ...any) (any, error)
Slice extracts a slice from a list between two indices.
Parameters:
list any - the list to slice. indices ...any - the start and optional end indices; if end is omitted,
slices to the end.
Returns:
any - the sliced part of the list. error - protect against undesired behavior due to migration to new signature.
For an example of this function in a Go template, refer to Sprout Documentation: slice.
func (*SlicesRegistry) SortAlpha ¶
func (sr *SlicesRegistry) SortAlpha(list any) []string
SortAlpha sorts a list of strings in alphabetical order.
Parameters:
list any - the list of strings to sort.
Returns:
[]string - the sorted list.
For an example of this function in a Go template, refer to Sprout Documentation: sortAlpha.
func (*SlicesRegistry) SplitList ¶
func (sr *SlicesRegistry) SplitList(sep string, value string) []string
SplitList divides a string into a slice of substrings separated by the specified separator.
! FUTURE: Rename this function to be more explicit
Parameters:
sep string - the delimiter used to split the string. value string - the string to split.
Returns:
[]string - a slice containing the substrings obtained from splitting the input string.
For an example of this function in a Go template, refer to Sprout Documentation: splitList.
func (*SlicesRegistry) StrSlice ¶
func (sr *SlicesRegistry) StrSlice(value any) []string
StrSlice converts a value to a slice of strings, handling various types including []string, []any, and other slice types.
Parameters:
value any - the value to convert to a slice of strings.
Returns:
[]string - the converted slice of strings.
For an example of this function in a Go template, refer to Sprout Documentation: strSlice.
func (*SlicesRegistry) UID ¶
func (sr *SlicesRegistry) UID() string
UID returns the unique identifier of the registry.
func (*SlicesRegistry) Uniq ¶
func (sr *SlicesRegistry) Uniq(list any) ([]any, error)
Uniq returns a new slice containing unique elements of the given list, preserving order.
Parameters:
list any - the list from which to remove duplicates.
Returns:
[]any - a list containing only the unique elements. error - error if the list is nil or not a slice/array.
For an example of this function in a Go template, refer to Sprout Documentation: uniq.
func (*SlicesRegistry) Until ¶
func (sr *SlicesRegistry) Until(count int) []int
Until generates a slice of integers from 0 up to but not including 'count'. If 'count' is negative, it produces a descending slice from 0 down to 'count', inclusive, with a step of -1. The function leverages UntilStep to specify the range and step dynamically.
Parameters:
count int - the endpoint (exclusive) of the range to generate.
Returns:
[]int - a slice of integers from 0 to 'count' with the appropriate step depending on whether 'count' is positive or negative.
For an example of this function in a Go template, refer to Sprout Documentation: until.
func (*SlicesRegistry) UntilStep ¶
func (sr *SlicesRegistry) UntilStep(start, stop, step int) []int
UntilStep generates a slice of integers from 'start' to 'stop' (exclusive), incrementing by 'step'. If 'step' is positive, the sequence increases; if negative, it decreases. The function returns an empty slice if the sequence does not make logical sense (e.g., positive step when start is greater than stop or vice versa).
Parameters:
start int - the starting point of the sequence. stop int - the endpoint (exclusive) of the sequence. step int - the increment between elements in the sequence.
Returns:
[]int - a dynamically generated slice of integers based on the input parameters, or an empty slice if the parameters are inconsistent with the desired range and step.
For an example of this function in a Go template, refer to Sprout Documentation: untilStep.
func (*SlicesRegistry) Without ¶
func (sr *SlicesRegistry) Without(args ...any) ([]any, error)
Without returns a new list excluding specified elements.
Parameters:
list any - the original list. omit ...any - elements to exclude from the new list.
Returns:
[]any - the list excluding the specified elements. error - protect against undesired behavior due to migration to new signature.
For an example of this function in a Go template, refer to Sprout Documentation: without.