https://github.com/reiver/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.
https://github.com/reiver/go-opt
maybe-type option-type optional-type
Last synced: about 2 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/reiver/go-opt
- Owner: reiver
- License: mit
- Created: 2017-05-18T18:19:16.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-08-09T03:53:41.000Z (10 months ago)
- Last Synced: 2025-04-09T09:46:32.682Z (about 2 months ago)
- Topics: maybe-type, option-type, optional-type
- Language: Go
- Homepage: https://godoc.org/github.com/reiver/go-opt
- Size: 41 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
[](https://godoc.org/github.com/reiver/go-opt)
## Examples
Here is an example **optional-type** that can hold a string:
```go
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](http://reiver.link)