...
Tawesoft Logo

Package variadic

import "tawesoft.co.uk/go/variadic"
Overview
Index

Overview ▾

Package variadic implements features that make it easier to work with variadic functions.

Package Information

License: MIT (see LICENSE.txt)

Stable: candidate

For more information, documentation, source code, examples, support, links, etc. please see https://www.tawesoft.co.uk/go and https://www.tawesoft.co.uk/go/variadic

func Flatten

func Flatten(args ...interface{}) []interface{}

Flatten takes a variable number of arguments and returns an array containing, in sequence, each argument or - if an argument is an array or a slice - that argument's contents.

e.g. Flatten(1, []int{2, 3, 4}, 5) => 1, 2, 3, 4, 5

func FlattenExcludingNils

func FlattenExcludingNils(args ...interface{}) []interface{}

FlattenExcludingNils takes a variable number of arguments and returns an array containing, in sequence, each non-nil argument or - if an argument is an array or a slice - that argument's non-nil contents.

e.g. FlattenExcludingNils(1, nil, []int{2, nil, 3, 4}, 5) => 1, 2, 3, 4, 5

func FlattenRecursive

func FlattenRecursive(args ...interface{}) []interface{}

FlattenRecursive takes a variable number of arguments and returns an array containing, in sequence, each argument or - if an argument is an array or a slice - that argument's contents, flattened recursively.

e.g. FlattenRecursive([]interface{}{1, 2, []int{3, 4}}, 5) => 1, 2, 3, 4, 5