slices

package
v0.0.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk

func Chunk(items []any, size int) [][]any

Chunk splits a slice into chunks of the specified size

Example: {{ slice.chunk .Slice 3 }} -> [[1 2 3] [4 5 6] [7 8 9]]

func Filter

func Filter(items []any, pred func(any) bool) []any

Filter returns a new slice containing only the elements that satisfy the predicate

Example: {{ slice.filter .Slice (lambda (x) (gt x 5)) }} -> [6 7 8 9]

func FuncMap

func FuncMap() template.FuncMap

FuncMap returns slice-specific functions

func Group

func Group(items []any, keyFn func(any) any) map[any][]any

Group groups slice elements by a key function

Example: {{ slice.group .Items (index . "key") }} -> map[key:[item1 item2] key2:[item3 item4]]

func Has

func Has(s []any, item any) bool

Has checks if a slice contains an item

Example: {{ slice.has .Slice "item" }}

func New

func New(items ...any) []any

New creates a new slice from the provided items

Example: {{ slice.new 1 2 3 4 5 }}

func Reverse

func Reverse(items []any) []any

Reverse reverses the elements in a slice

Example: {{ slice.reverse .Slice }} -> [5 4 3 2 1]

func Sort

func Sort(items []any) []any

Sort sorts a slice in ascending order

Example: {{ slice.sort .Slice }} -> [1 2 3 4 5]

func Unique

func Unique(items []any) []any

Unique returns unique elements from a slice

Example: {{ slice.unique .Slice }} -> [1 2 3 4 5]

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL