Categorygithub.com/rkennedy/optional
repositorypackage
0.0.0-20240805175357-31046fb46426
Repository: https://github.com/rkennedy/optional.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

optional

The optional package provides an option type, which can either be empty or hold a value. In that respect, it's very similar to an ordinary pointer type, except it has methods that make its possible emptiness more explicit.

The interface of the optional.Value type is modeled on Java's java.util.Optional type and C++'s std::optional.

Usage

go get github.com/rkennedy/optional
import github.com/rkennedy/optional
full := optional.New(42)
empty := optional.Value[int]{}

fmt.Printf("full: %v\n", full)  // Output: 42
fmt.Printf("empty: %v\n", empty) // Output: None