flat

package
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 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

Jump to

Keyboard shortcuts

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