Documentation
¶
Overview ¶
Package flat provides functions to recursively flatten a slice of slices.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Flat ¶
func Flat(in interface{}) interface{}
Flat recursively flattens a slice of slices. Flat attempts to maintain the slice type if possible.
Example ¶
in := []interface{}{
[]interface{}{
"a",
"b",
"c",
},
[]int{1, 2, 3},
[]interface{}{},
"d",
"e",
"f",
}
out := Flat(in)
fmt.Printf("%#v\n", out)
Output: []interface {}{"a", "b", "c", 1, 2, 3, "d", "e", "f"}
func FlatDepth ¶
FlatDepth recursively flattens a slice of slices to a maximum depth. FlatDepth attempts to maintain the slice type if possible. If maxDepth is less than zero, then there is no maximum depth.
Example ¶
in := []interface{}{
[]interface{}{
"a",
[]interface{}{
"b",
[]interface{}{
"c",
"d",
"e",
},
},
},
}
maxDepth := 1
out := FlatDepth(in, 0, maxDepth)
fmt.Printf("%#v\n", out)
Output: []interface {}{"a", "b", []interface {}{"c", "d", "e"}}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.