result

command module
v0.0.0-...-ee6ab61 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

README

go-composites/result

result

ci

The result composite of go-composites — the value every fallible operation returns. A Result pairs a payload with an Error, so success and failure travel together as one value: no (value, ok), no panics, no bare nil. A fresh Result.New() defaults to a Null payload and a NullError, so it represents a successful, empty outcome.

Install

go get github.com/go-composites/result

API

symbol returns notes
New(opts...) Result.Interface payload defaults to Null, error to NullError
WithPayload(v) Option functional option setting the payload
WithError(e) Option functional option setting the Error.Interface
Payload() interface{} the carried payload
HasError() bool !Error.IsNull()true only when a real error is attached
Error() Error.Interface the carried error (a NullError when there is none)

Usage

package main

import (
	"fmt"

	Result "github.com/go-composites/result/src"
	Error "github.com/go-composites/error/src"
)

func main() {
	ok := Result.New(Result.WithPayload(42))
	fmt.Println(ok.HasError(), ok.Payload()) // false 42

	bad := Result.New(Result.WithError(Error.New("key not found")))
	fmt.Println(bad.HasError(), bad.Error().Message()) // true key not found

	empty := Result.New()
	fmt.Println(empty.HasError()) // false  (Null payload + NullError)
}

License

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

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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