Documentation ¶
Overview ¶
Package helper provides common methods used by the various template functions
Index ¶
- Constants
- Variables
- func Apply[T, U any](a []T, fn func(T) (U, error)) ([]U, error)
- func AsStringList(list any) ([]string, error)
- func Combine[M ~map[K]V, K comparable, V any](maps ...M) M
- func ItemForList(item any) reflect.Value
- func ListInfo(list any) (slice reflect.Value, length int, err error)
- func NewTemplate(t *testing.T, tpl string, fns template.FuncMap) *template.Template
- func PtrTo[T any](t T) *T
- func Reduce[T, U any](a []T, initial U, fn Reducer[T, U]) U
- func TemplateTest(test TestSet, fns template.FuncMap) func(t *testing.T)
- func ToFloat(a any) (float64, error)
- type Reducer
- type TestArgs
- type TestSet
Constants ¶
const TestTemplateName = "test template"
TestTemplateName is the template name used for testing
Variables ¶
var Now = time.Now
Now is defined as a variable so that it can be overridden as required (e.g. unit testing)
Functions ¶
func Apply ¶ added in v0.10.3
Apply a function to each element of a slice, returning a translated slice
func AsStringList ¶
AsStringList converts a list to a list of strings
func Combine ¶ added in v0.10.3
func Combine[M ~map[K]V, K comparable, V any](maps ...M) M
Combine a slice of maps into a single map, with key collisions, later overwrites earlier
func ItemForList ¶
ItemForList returns the item as a reflect.Value that can be inserted into the list. This is because nil requires special casing
func ListInfo ¶
ListInfo returns basic info that we need for most list processing, ie it's reflect.Value (converted to the generic []any type), length, or error message if it's not a list
func NewTemplate ¶
NewTemplate creates a new template
func PtrTo ¶ added in v0.10.3
func PtrTo[T any](t T) *T
PtrTo returns a pointer to a copy of the given parameter
func Reduce ¶ added in v0.10.3
Reduce an array to a single value through successive calls to a function that takes the previous value and the next element of the array
func TemplateTest ¶
TemplateTest generates a test function for a given TestSet. fns is a set of functions needed by the template to be rendered
Types ¶
type Reducer ¶ added in v0.10.3
type Reducer[T, U any] func(a U, b T) U
Reducer is the signature for a reduction method used by Reduce