Common

package
v0.2.37 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean(elem any)

Clean removes all the elements from the data structure by calling the Clean method if the element implements the Cleaner interface.

Parameters:

  • cleaner: The data structure to clean.

func CopyOf

func CopyOf(elem any) any

CopyOf creates a copy of the element by either calling the Copy method if the element implements the Copier interface or returning the element as is.

Parameters:

  • elem: The element to copy.

Returns:

  • any: A copy of the element.

func EqualOf

func EqualOf(obj1, obj2 any) bool

EqualOf compares two objects of the same type. If any of the objects implements the Equaler interface, the Equals method is called. Otherwise, the objects are compared using the == operator. However, obj1 is always checked first.

Parameters:

  • obj1: The first object to compare.
  • obj2: The second object to compare.

Returns:

  • bool: True if the objects are equal, false otherwise.

Behaviors:

  • Nil objects are always considered different.

func SliceOf

func SliceOf[T any](elem any) []T

SliceOf converts any type to a slice of elements of the same type.

Parameters:

  • elem: The element to convert to a slice.

Returns:

  • []T: The slice representation of the element.

Behaviors:

  • Nil elements are converted to nil slices.
  • Slice elements are returned as is.
  • Slicer elements have their Slice method called.
  • Other elements are converted to slices containing a single element.

func StringOf

func StringOf(elem any) string

StringOf converts any type to a string.

Parameters:

  • elem: The element to convert to a string.

Returns:

  • string: The string representation of the element.

Behaviors:

  • String elements are returned as is.
  • fmt.Stringer elements have their String method called.
  • error elements have their Error method called.
  • []byte and []rune elements are converted to strings.
  • Other elements are converted to strings using fmt.Sprintf and the %v format.

Types

type Cleaner

type Cleaner interface {
	// Clean removes all the elements from the data structure.
	Clean()
}

Cleaner is an interface that provides a method to remove all the elements from a data structure.

type Comparable

type Comparable interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64 | ~string
}

Comparable is an interface that defines the behavior of a type that can be compared with other values of the same type using the < and > operators. The interface is implemented by the built-in types int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, and string.

type Copier

type Copier interface {
	// Copy creates a shallow copy of the object.
	//
	// Returns:
	//   - Copier: A shallow copy or a deep copy of the object.
	Copy() Copier
}

Copier is an interface that provides a method to create a deep copy of an object.

type DoFunc

type DoFunc[T any] func(T)

DoFunc is a generic type that represents a function that takes a value and does something with it.

Parameters:

  • T: The type of the value.

type DualDoFunc

type DualDoFunc[T any, U any] func(T, U)

DualDoFunc is a generic type that represents a function that takes two values and does something with them.

Parameters:

  • T: The type of the first value.
  • U: The type of the second value.

type Equaler

type Equaler[T any] interface {
	// Equals returns true if the object is equal to the other object.
	//
	// Parameters:
	// 	- other: The other object to compare to.
	//
	// Returns:
	// 	- bool: True if the object is equal to the other object.
	Equals(other T) bool
}

Equaler is an interface that defines a method to compare two objects of the same type.

type ObserverFunc

type ObserverFunc[T any] func(T) error

ObserverFunc is a function type that takes a value of type T and returns an error. It is used to observe the values of the nodes during a traversal.

type Slicer

type Slicer[T any] interface {
	// The Slice method returns a slice containing all the elements in the data structure.
	Slice() []T
}

Slicer is an interface that provides a method to convert a data structure to a slice.

Jump to

Keyboard shortcuts

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