https://github.com/eth-p/go-goptional
Optional type using Go 1.18 generics.
https://github.com/eth-p/go-goptional
Last synced: about 1 year ago
JSON representation
Optional type using Go 1.18 generics.
- Host: GitHub
- URL: https://github.com/eth-p/go-goptional
- Owner: eth-p
- License: mit
- Created: 2022-01-15T08:28:29.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-15T09:12:30.000Z (over 4 years ago)
- Last Synced: 2025-02-09T00:26:01.772Z (over 1 year ago)
- Language: Go
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# go.eth-p.dev/goptional
**G**eneric **Optional** (or **G**o **Optional**, if you prefer)
`goptional` is a package that provides an implementation of an `Optional[T]` monad using Go 1.18 generics.
## Installation
```go
import (
"go.eth-p.dev/goptional"
)
```
## Why goptional?
- [x] Prevents you from using uninitialized values.
- [x] No code generation required.
- [x] Type-safe API.
- [ ] Supports marshalling and unmarshalling. (TODO)
## Example
```go
import (
"os"
optional "go.eth-p.dev/goptional"
)
func getConfigDirectory() optional.Optional[string] {
return optional.From(os.LookupEnv("XDG_CONFIG_HOME"))
}
func main() {
configDir := getConfigDirectory().
UnwrapOr("~/.config")
println(configDir)
}
```
For more detailed examples, feel free to check out the [examples directory](examples).
## License
[MIT License](LICENSE.md)