reflect

package
v0.0.0-...-6fe5fd8 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: Apache-2.0, BSD-3-Clause Imports: 3 Imported by: 0

README

This was originally forked from https://github.com/golang/go/blob/master/src/reflect/deepequal.go in order to

  • consider empty lists and empty maps equal to their nil counterparts
  • add a AddFuncs mechanism to add custom equality funcs for specific types.

Meanwhile it has diverged quite a lot while still following the original algorithm at the core though.

Documentation

Overview

Package reflect is a fork of go's standard library reflection package, which allows for deep equal with equality functions defined.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Equalities

type Equalities map[reflect.Type]reflect.Value

Equalities is a map from type to a function comparing two values of that type.

func EqualitiesOrDie

func EqualitiesOrDie(funcs ...interface{}) Equalities

EqualitiesOrDie adds the given funcs and panics on any error.

func (Equalities) AddFunc

func (e Equalities) AddFunc(eqFunc interface{}) error

AddFunc uses func as an equality function: it must take two parameters of the same type, and return a boolean.

func (Equalities) AddFuncs

func (e Equalities) AddFuncs(funcs ...interface{}) error

AddFuncs is a shortcut for multiple calls to AddFunc.

func (Equalities) DeepDerivative

func (e Equalities) DeepDerivative(a1, a2 interface{}) bool

DeepDerivative is similar to DeepEqual except that unset fields in a1 are ignored (not compared). This allows us to focus on the fields that matter to the semantic comparison.

The unset fields include a nil pointer and an empty string.

func (Equalities) DeepEqual

func (e Equalities) DeepEqual(a1, a2 interface{}) bool

DeepEqual is like reflect.DeepEqual, but focused on semantic equality instead of memory equality.

It will use e's equality functions if it finds types that match.

An empty slice *is* equal to a nil slice for our purposes; same for maps.

Unexported field members cannot be compared and will cause an informative panic; you must add an Equality function for these types.

Jump to

Keyboard shortcuts

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