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.
Go to file
Charles Iliya Krempeaux d4de6ca5ee json.ErrorEmpty 2024-08-08 10:58:13 -07:00
LICENSE changelog.ca -> reiver.link 2024-07-04 09:44:29 -07:00
README.md sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
errors.go json.ErrorEmpty 2024-08-08 10:58:13 -07:00
go.mod json.ErrorEmpty 2024-08-08 10:58:13 -07:00
go.sum json.ErrorEmpty 2024-08-08 10:58:13 -07:00
map.go opt.Optional[T].IsNothing() opt.Optional[T].IsSomething() 2024-06-16 07:03:11 -07:00
map_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional.go opt.Optional[T].IsNothing() opt.Optional[T].IsSomething() 2024-06-16 07:03:11 -07:00
optional_filter_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_get_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_getelse_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_gostring_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_isnothing.go opt.Optional[T].IsNothing() opt.Optional[T].IsSomething() 2024-06-16 06:42:51 -07:00
optional_isnothing_int_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_issomething.go opt.Optional[T].IsNothing() opt.Optional[T].IsSomething() 2024-06-16 06:42:51 -07:00
optional_issomething_int_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_marshaljson.go json.ErrorEmpty 2024-08-08 10:58:13 -07:00
optional_marshaljson_bool_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_marshaljson_int_test.go json.ErrorEmpty 2024-08-08 10:58:13 -07:00
optional_marshaljson_string_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_unmarshaljson.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_unmarshaljson_bool_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_unmarshaljson_int64_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_unmarshaljson_int_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_unmarshaljson_string_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_unmarshaljson_uint64_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_whennothing_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
optional_whensomething_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00
then.go opt.Optional[T].IsNothing() opt.Optional[T].IsSomething() 2024-06-16 07:03:11 -07:00
then_test.go sourcecode.social -> github.com 2024-07-04 09:54:41 -07:00

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

GoDoc

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 follownig:

import "github.com/reiver/go-opt"

Installation

To install package opt do the following:

GOPROXY=direct go get https://github.com/reiver/go-opt

Author

Package opt was written by Charles Iliya Krempeaux