Charles Iliya Krempeaux 9cbd049b34 | ||
---|---|---|
LICENSE | ||
README.md | ||
go.mod | ||
go.sum | ||
optional.go | ||
optional_get_test.go | ||
optional_gostring_test.go | ||
optional_whennothing_test.go | ||
optional_whensomething_test.go |
README.md
go-opt
Package opt implements an optional-type, for the Go programming language.
In other programming languages, an optional-type might be know as: a option type, or a maybe type.
Documention
Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-opt
Examples
Here is an example optional-type that can hold a string:
var op opt.Optional[string] // the default value is nothing.
// ...
if opt.Nothing[string]() == op {
fmt.Println("nothing")
}
// ...
switch op {
case op.Nothing[string]():
//@TODO
case op.Something("apple"):
//@TODO
case op.Something("banana"):
//@TODO
case op.Something("cherry"):
//@TODO
default:
//@TODO
}
// ...
value, found := op.Get()
if {
fmt.Println("VALUE:", value)
} else {
fmt.Println("nothing")
}