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 afc1a40c4b made it so UnmarhsalJSON works with *int64 *uint64 *json.Number 2024-02-24 09:50:00 -08:00
LICENSE change contact info in LICENSE 2022-08-08 08:57:37 -07:00
README.md correction 2023-10-27 11:33:08 -07:00
go.mod improvements 2023-09-27 09:43:16 +09:00
go.sum improvements 2023-09-27 09:43:16 +09: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 .GetElse() 2023-11-05 01:20:57 -07: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_getelse_test.go .GetElse() 2023-11-05 01:20:57 -07: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 improvements 2023-09-27 09:43:16 +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 made it so UnmarhsalJSON works with *int64 *uint64 *json.Number 2024-02-24 09:50:00 -08:00
optional_unmarshaljson_bool_test.go .UnmarshalJSON() 2023-09-24 06:27:34 +09:00
optional_unmarshaljson_int64_test.go made it so UnmarhsalJSON works with *int64 *uint64 *json.Number 2024-02-24 09:50:00 -08: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_unmarshaljson_uint64_test.go made it so UnmarhsalJSON works with *int64 *uint64 *json.Number 2024-02-24 09:50:00 -08: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")
}

Import

To import package opt use import code like the follownig:

import "sourcecode.social/reiver/go-opt"

Installation

To install package opt do the following:

GOPROXY=direct go get https://sourcecode.social/reiver/go-opt

Author

Package opt was written by Charles Iliya Krempeaux