flat

package
Version: v0.0.0-...-7d52044 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2021 License: MIT Imports: 2 Imported by: 1

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

func FlatDepth(in interface{}, depth int, maxDepth int) interface{}

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.

Source Files

Jump to

Keyboard shortcuts

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