An open API service indexing awesome lists of open source software.

https://github.com/otterize/nilable

nilable is a tiny Go generics library for making non-nilable values nilable
https://github.com/otterize/nilable

Last synced: 6 months ago
JSON representation

nilable is a tiny Go generics library for making non-nilable values nilable

Awesome Lists containing this project

README

          

# nilable
nilable is a tiny Go generics library for making non-`nil`able values nilable, and supports JSON serialization.

You too can stop using pointers when you don't need them!

## From value to JSON
```go
nilableString := nilable.From("hello world")
println(nilableString.Set) // true
println(nilableString.Item) // "hello world"
data, _ := json.Marshal(nilableString)
println(string(data)) // `"hello world"`
```

## From null JSON to value
```go
var nilableString Nilable[string]
json.Unmarshal([]byte("null"), &nilJson)
println(nilJson.Set) // false
```