Charles Iliya Krempeaux 92d6f78ad6 | ||
---|---|---|
LICENSE | ||
README.md | ||
errors.go | ||
go.mod | ||
go.sum | ||
map.go | ||
map_test.go | ||
optional.go | ||
optional_filter_test.go | ||
optional_get_test.go | ||
optional_getelse_test.go | ||
optional_gostring_test.go | ||
optional_isnothing.go | ||
optional_isnothing_int_test.go | ||
optional_issomething.go | ||
optional_issomething_int_test.go | ||
optional_marshaljson.go | ||
optional_marshaljson_bool_test.go | ||
optional_marshaljson_int_test.go | ||
optional_marshaljson_string_test.go | ||
optional_unmarshaljson.go | ||
optional_unmarshaljson_bool_test.go | ||
optional_unmarshaljson_int64_test.go | ||
optional_unmarshaljson_int_test.go | ||
optional_unmarshaljson_string_test.go | ||
optional_unmarshaljson_uint64_test.go | ||
optional_whennothing_test.go | ||
optional_whensomething_test.go | ||
then.go | ||
then_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:
import "github.com/reiver/go-opt"
//
var op opt.Optional[string] // the default value is nothing.
// ...
if opt.Nothing[string]() == op {
fmt.Println("nothing")
}
// ...
op = opt.Something("Hello world! 👾")
// ...
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 found {
fmt.Println("VALUE:", value)
} else {
fmt.Println("nothing")
}
Import
To import package opt use import
code like the following:
import "github.com/reiver/go-opt"
Installation
To install package opt do the following:
GOPROXY=direct go get github.com/reiver/go-opt
Author
Package opt was written by Charles Iliya Krempeaux