Documentation
¶
Overview ¶
Package arity contains helpers for working with variadic functions.
Index ¶
- func Listify(array interface{}) ([]interface{}, error)
- func ListifyOrPanic(array interface{}) []interface{}
- func Optional(offset int, limit int, def interface{}, args ...interface{}) interface{}
- func OptionalUntyped(offset int, limit int, def interface{}, args interface{}) interface{}
- func Sole(def interface{}, args ...interface{}) interface{}
- func SoleUntyped(def interface{}, args interface{}) interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Listify ¶
func Listify(array interface{}) ([]interface{}, error)
Listify converts a potential array or slice into a slice of empty interfaces, returning an error if 'array' is not an array/slice.
func ListifyOrPanic ¶
func ListifyOrPanic(array interface{}) []interface{}
ListifyOrPanic functions like Listify, but will panic instead of returning an error.
func Optional ¶
Optional extracts the argument from args at the given offset if len(args) > offset, returning the specified default if args is not long enough. If args contains more elements than limit, the function panics. Useful for implementing optional arguments of variable arity, while enforcing their length.
func OptionalUntyped ¶
OptionalUntyped is a variation of Optional that is liberal in the type of argument array that it accepts, using ListifyOrPanic to convert any array/slice.
func Sole ¶
func Sole(def interface{}, args ...interface{}) interface{}
Sole extracts the optional sole argument from args if len(args) == 0, returning the specified default if args is empty. If args contains multiple elements, the function panics.
func SoleUntyped ¶
func SoleUntyped(def interface{}, args interface{}) interface{}
SoleUntyped is a variation of Sole that is liberal in the type of argument array that it accepts, using ListifyOrPanic to convert any array/slice.
Types ¶
This section is empty.