Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pair ¶
type Pair[F, S any] struct { // contains filtered or unexported fields }
Pair of two elements of different/same types.
func Of ¶
Of returns a new pair with the given elements.
Example ¶
p1 := Of("first", "second") fmt.Println(p1) fmt.Println(p1.First()) fmt.Println(p1.Second()) p2 := Of(42, errors.New("something went wrong")) fmt.Println(p2)
Output: ("first", "second") first second (42, &errors.errorString{s:"something went wrong"})
func (Pair[F, S]) First ¶
func (p Pair[F, S]) First() F
First returns the first element of the pair.
func (Pair[F, S]) MarshalJSON ¶
MarshalJSON implements the json.Marshaler.
Example ¶
p := Of(42, "hello") b, err := p.MarshalJSON() if err != nil { fmt.Println(err) return } fmt.Println(string(b))
Output: {"key":42,"value":"hello"}
func (Pair[F, S]) Second ¶
func (p Pair[F, S]) Second() S
Second returns the second element of the pair.
func (*Pair[F, S]) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler.
Example ¶
raw := []byte(`{"key":42,"value":"hello"}`) var p Pair[int, string] if err := json.Unmarshal(raw, &p); err != nil { panic(err) } fmt.Println(p)
Output: (42, "hello")
Click to show internal directories.
Click to hide internal directories.