arity

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: BSD-3-Clause Imports: 2 Imported by: 4

Documentation

Overview

Package arity contains helpers for working with variadic functions.

Index

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

func Optional(offset int, limit int, def interface{}, args ...interface{}) interface{}

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

func OptionalUntyped(offset int, limit int, def interface{}, args interface{}) interface{}

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.

Jump to

Keyboard shortcuts

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