interfacetricks

package
v0.24.3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(value interface{}) interface{}

Create a copy of a value, so we can modify it in place.

func Equal

func Equal(left interface{}, right interface{}) bool

Recursively test equality of two value trees.

func IntersectWith

func IntersectWith(
	left interface{},
	right interface{},
	resolve func(l interface{}, r interface{}) interface{},
) interface{}

Create a new object or array containing only the parts that were in both trees. The values in the new tree are determined by the resolve argument.

func Merge

func Merge(left interface{}, right interface{}) interface{}

Merges two value trees recursively. If there is a conflict, the right value is retained.

func MergeObjects

func MergeObjects(left map[string]interface{}, right map[string]interface{}) map[string]interface{}

Like `Merge` but has a more useful return type if you're merging objects.

func MergeWith

func MergeWith(
	left interface{},
	right interface{},
	conflict func(interface{}, interface{}) interface{},
) interface{}

MergeWith is like Merge but allows you to customize what happens on a conflict.

func TopDownWalk

func TopDownWalk(w TopDownWalker, value interface{}) interface{}

Types

type TopDownWalker

type TopDownWalker interface {
	WalkArray([]interface{}) (interface{}, bool)
	WalkObject(map[string]interface{}) (interface{}, bool)

	WalkString(string) (interface{}, bool)
	WalkBool(bool) (interface{}, bool)
}

This is a utility for recursively transforming JSON-like interface values in go.

At every step, the transformer returns the new value as well as an indication of whether or not we should continue.

Jump to

Keyboard shortcuts

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