Documentation
¶
Overview ¶
Package flatten flattens arrays and slices.
Features
- Accept any number of arguments.
- Process complex or simple nested arrays or slices.
- Process any type of array or slice.
- Has no external dependency
- Code follows the standard Golang format
Usage
import "github.com/thalesfsp/flatten"
analysis
flatten pass a rigid set of analysis, including `gosec`. To analyze the code, just run:
make analyze
_Note that you will have to have such tools previously installed. The command will print out a list._
Tests Code has 100% coverage. To test, just run:
make test
Benchmark All functions are benchmarked. To benchmark, just run:
make benchmark
Documentation ¶
flatten code is well documented, please check the comments.
Example ¶
// The following code demonstrates how to flatten a 4D array and assumes // that the flatten package has already been imported. // Multidimensional array (4D) const rolls = 4 const columns = 4 var fourD [rolls][columns]int // Generator/filler for roll := 0; roll < rolls; roll++ { for column := 0; column < columns; column++ { fourD[roll][column] = (roll + 1) + (column * 2) } } result, err := Flatten(fourD) if err != nil { panic(err) } fmt.Println(result)
Output: [1 3 5 7 2 4 6 8 3 5 7 9 4 6 8 10]
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Flatten ¶
func Flatten(anything ...interface{}) ([]interface{}, error)
Flatten is a proxy to `flattenDeep` (private), wrapping and allowing it to process anything. It also provides an additional layer of protection, by not allowing empty interfaces to be processed, which could cause an cyclic problem (infinity recursion)
Types ¶
This section is empty.