The Null-Object primitive of go-composites.
Null is the inert, never-nil value that the other composites reach for when
they need an absence that still honours an interface rather than a bare Go
nil. It is the default payload of a fresh
Result, so "no value yet" is itself
a value.
go get github.com/go-composites/null| symbol | kind | notes |
|---|---|---|
Interface |
type | interface { IsNull() bool } — the Null-Object contract |
New() |
Interface |
returns a fresh, inert Null-Object |
IsNull() |
bool |
always true on a Null — the defining predicate |
package main
import (
"fmt"
Null "github.com/go-composites/null/src"
Result "github.com/go-composites/result/src"
)
func main() {
n := Null.New()
fmt.Println(n) // an inert Null-Object, not nil
// A fresh Result carries a Null payload by default.
r := Result.New()
fmt.Println(r.HasError()) // false
fmt.Println(r.Payload()) // the Null-Object
}BSD-3-Clause © the go-composites/null authors.
