The pair package provides a concrete implementation of a Pair of values. A Pair is a data structure that holds two values of any type.
To use the pair package, import it into your project:
import (
...
"github.com/arthurcgc/pair"
...
)To create a new pair, use the NewPair function:
p := pair.NewPair(1, 2.0)To get the first and second values of the pair, use the First and Second methods, respectively:
p := pair.NewPair(1, "hello")
fmt.Println(p.First) // 1
fmt.Println(p.Second) // helloTo get the string representation of the pair, use the String method:
p := pair.NewPair(1, 2.0)
fmt.Println(p.String()) // (1, 2.0)To check if two pairs are equal, use the Equals function:
p1 := pair.NewPair(1, 2)
p2 := pair.NewPair(1, 2)
fmt.Println(Equals(p1, p2)) // truep1 := pair.NewPair(1, "hello")
p2 := pair.NewPair(1, "world")
fmt.Println(Equals(p1, p2)) // falseThe Pair package supports the following types:
intint32int64uintuint32uint64float32float64stringbool
I intend to add support for more types in the future.
This project is licensed under the MIT License - see the LICENSE file for details.