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 3e7cdb405e .MarshalJSON() 2023-09-25 11:35:13 +09:00
LICENSE change contact info in LICENSE 2022-08-08 08:57:37 -07:00
README.md github.com/reiver/go-opt -> sourcecode.social/reiver/go-opt 2023-09-23 05:40:21 +09:00
go.mod github.com/reiver/go-opt -> sourcecode.social/reiver/go-opt 2023-09-23 05:40:21 +09:00
go.sum opt.Optional[T] 2022-08-08 10:01:41 -07:00
map.go .isnothing() 2023-09-24 05:24:56 +09:00
map_test.go github.com/reiver/go-opt -> sourcecode.social/reiver/go-opt 2023-09-23 05:40:21 +09:00
optional.go .isnothing() 2023-09-24 05:24:56 +09:00
optional_filter_test.go github.com/reiver/go-opt -> sourcecode.social/reiver/go-opt 2023-09-23 05:40:21 +09:00
optional_get_test.go github.com/reiver/go-opt -> sourcecode.social/reiver/go-opt 2023-09-23 05:40:21 +09:00
optional_gostring_test.go github.com/reiver/go-opt -> sourcecode.social/reiver/go-opt 2023-09-23 05:40:21 +09:00
optional_marshaljson.go .MarshalJSON() 2023-09-25 11:35:13 +09:00
optional_marshaljson_bool_test.go more tests 2023-09-24 05:30:44 +09:00
optional_marshaljson_int_test.go more tests 2023-09-24 05:44:49 +09:00
optional_marshaljson_string_test.go more tests 2023-09-24 05:30:44 +09:00
optional_unmarshaljson.go .UnmarshalJSON() 2023-09-25 07:04:29 +09:00
optional_unmarshaljson_bool_test.go .UnmarshalJSON() 2023-09-24 06:27:34 +09:00
optional_unmarshaljson_int_test.go .UnmarshalJSON() 2023-09-24 06:27:34 +09:00
optional_unmarshaljson_string_test.go .UnmarshalJSON() 2023-09-24 06:27:34 +09:00
optional_whennothing_test.go github.com/reiver/go-opt -> sourcecode.social/reiver/go-opt 2023-09-23 05:40:21 +09:00
optional_whensomething_test.go github.com/reiver/go-opt -> sourcecode.social/reiver/go-opt 2023-09-23 05:40:21 +09:00
then.go .isnothing() 2023-09-24 05:24:56 +09:00
then_test.go github.com/reiver/go-opt -> sourcecode.social/reiver/go-opt 2023-09-23 05:40:21 +09: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/sourcecode.social/reiver/go-opt

GoDoc

Examples

Here is an example optional-type that can hold a string:

import "sourcecode.social/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")
}