Pair

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractFirsts added in v0.3.0

func ExtractFirsts[A any, B any](pairs []*Pair[A, B]) []A

ExtractFirsts extracts all the first elements from the given slice of pairs.

Parameters:

  • pairs: The slice of pairs.

Returns:

  • []A: The slice of first elements.

Behaviors:

  • If the slice is empty, the function returns nil.
  • If the slice contains only nil pairs, the function returns nil.
  • This has the side effect of modifying the original slice when at least one nil pair is found. BEWARE!

func ExtractSeconds added in v0.3.0

func ExtractSeconds[A any, B any](pairs []*Pair[A, B]) []B

ExtractSeconds extracts all the second elements from the given slice of pairs.

Parameters:

  • pairs: The slice of pairs.

Returns:

  • []B: The slice of second elements.

Behaviors:

  • If the slice is empty, the function returns nil.
  • If the slice contains only nil pairs, the function returns nil.
  • This has the side effect of modifying the original slice when at least one nil pair is found. BEWARE!

Types

type Pair

type Pair[A any, B any] struct {
	// The first value.
	First A

	// The second value.
	Second B
}

Pair is a pair of values.

func NewPair

func NewPair[A any, B any](first A, second B) *Pair[A, B]

NewPair creates a new pair.

Parameters:

  • first: The first value.
  • second: The second value.

Returns:

  • Pair[A, B]: The new pair.

func RemoveNilPairs added in v0.3.0

func RemoveNilPairs[A any, B any](pairs []*Pair[A, B]) []*Pair[A, B]

RemoveNilPairs removes all nil pairs from the given slice of pairs.

Parameters:

  • pairs: The slice of pairs.

Returns:

  • []*Pair[A, B]: The slice of pairs without nil pairs.

Behaviors:

  • If the slice is empty, the function returns nil.
  • This has the side effect of modifying the original slice when at least one nil pair is found. BEWARE!

func (*Pair[A, B]) Clean

func (p *Pair[A, B]) Clean()

Clean cleans the pair by first calling the intf.Clean() function on both the first and second values and then setting them to their zero values.

func (*Pair[A, B]) Copy

func (p *Pair[A, B]) Copy() intf.Copier

Copy returns a shallow or deep copy of the pair according to the function intf.CopyOf().

Returns:

  • intf.Copier: A shallow or deep copy of the pair.

func (*Pair[A, B]) Equals

func (p *Pair[A, B]) Equals(other *Pair[A, B]) bool

Equals returns true if the pair is equal to the other pair according to the function intf.EqualOf().

Parameters:

  • other: The other pair to compare to.

Returns:

  • bool: True if the pair is equal to the other pair.

func (*Pair[A, B]) String

func (p *Pair[A, B]) String() string

String returns a string in the following format: (first, second). Here, both first and second are determined by the intf.StringOf() function.

Returns:

  • string: The string representation of the pair.

Jump to

Keyboard shortcuts

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