Skip to content

go-composites/pair

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-composites/pair

pair

ci

The two-element composite of go-composites. A Pair is a fixed, heterogeneous grouping of two values — the natural key/value entry. It is interface-first and never goes nil: the Null-Object Pair honours the whole Interface.

Install

go get github.com/go-composites/pair

Usage

package main

import (
    "fmt"

    Pair "github.com/go-composites/pair/src"
)

func main() {
    entry := Pair.New("answer", 42)

    fmt.Println(entry.ToGoString())                    // (answer, 42)
    fmt.Println(entry.First())                         // answer
    fmt.Println(entry.Second())                        // 42
    fmt.Println(entry.Equal(Pair.New("answer", 42)))   // true
    fmt.Println(entry.ToArray().Len())                 // 2
}

API

Constructors

  • New(first, second interface{}) Interface — a Pair holding the two values.
  • Null() Interface — the Null-Object Pair.

Methods

method returns notes
First() interface{} the first slot
Second() interface{} the second slot
Equal(other) Go bool both slots reflect.DeepEqual (false against a null Pair)
ToArray() Array.Interface a two-element [first, second] Array
ToGoString() Go string "(first, second)" ("(null)" for the Null-Object)
IsNull() Go bool true only for the Null-Object

Null-Object

Null() returns the never-nil Null-Object Pair: its slots are nil, it Equals nothing (not even another null Pair), ToArray() is the empty Array, and ToGoString() renders "(null)". IsNull() reports true for it.

License

BSD-3-Clause © the go-composites/pair authors.

About

A two-element Pair composite for Composition-Oriented Programming — the natural key/value entry, Null-Object, never nil

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages