Releases: moznion/go-optional
v0.12.0
Since this version, it begins supporting to handle the values of any type which supported by database/sql
on Scan
and Value
functions in that sql package. Thank you for the contributions, @RangelReale and @nikhrom.
New Features
- Use default sql package functions for Scanner and Valuer #32 @RangelReale
- Use
go:linkname
fordatabase/sql.convertAssign
#33 @moznion
Bug Fixes
Maintenance
- Support go 1.21.x on CI #34 @moznion
- Update module github.com/mattn/go-sqlite3 to v1.14.18 #35 @renovate-bot
- Update module github.com/mattn/go-sqlite3 to v1.14.19 #36 @renovate-bot
- Update module github.com/mattn/go-sqlite3 to v1.14.22 #38 @renovate-bot
- Update module github.com/stretchr/testify to v1.9.0 #39 @renovate-bot
v0.11.0
New Features
- Implements
database/sql/driver.Valuer
anddatabase/sql.Scanner
on Option type #30 - Support
UnwrapAsPtr()
method to unwrap the Option value as a pointer #28
Maintenance
- Add the target golang runtime version 1.20.x for CI #29
- Update module github.com/stretchr/testify to v1.8.4 #26
- Update module github.com/stretchr/testify to v1.8.3 #24
- Update module github.com/stretchr/testify to v1.8.2 #23
Documents
- Document for
UnwrapAsPtr
#31
v0.10.0
v0.9.0
v0.8.0
v0.7.0
New Features
Support two value factory methods: FromNillable()
and PtrFromNillable()
#18
These methods accept the nillable pointer value as an argument and make the Optional[T]
type value.
FromNillable()
If the given value is not nil, this returns Some[T]
value with doing value-dereference.
On the other hand, if the value is nil, this returns None[T]
.
example:
num := 123
some := FromNillable[int](&num)
fmt.Printf("%v\n", some.IsSome()) // => true
fmt.Printf("%v\n", some.Unwrap()) // => 123
none := FromNillable[int](nil)
fmt.Printf("%v\n", none.IsSome()) // => false
fmt.Printf("%v\n", none.Unwrap()) // => 0 (the default value of int)
PtrFromNillable()
If the given value is not nil, this returns Some[*T]
value without doing value-dereference.
On the other hand, if the value is nil, this returns None[*T]
.
example:
num := 123
some := PtrFromNillable[int](&num)
fmt.Printf("%v\n", some.IsSome()) // => true
fmt.Printf("%v\n", *some.Unwrap()) // => 123 (NOTE: it needs doing dereference)
none := PtrFromNillable[int](nil)
fmt.Printf("%v\n", none.IsSome()) // => false
fmt.Printf("%v\n", none.Unwrap()) // => nil
v0.6.0
New Features
Support omitempty
option on JSON marshaling #17
This version brings up the support for the omitempty
option on JSON marshaling. If the property has that option and the value is None[T]
, it omits that property from the serialized JSON string.
example:
type JSONStruct struct {
OmitemptyVal Option[string] `json:"omitemptyVal,omitempty"` // this should be omitted
}
jsonStruct := &JSONStruct{OmitemptyVal: None[string]()}
marshal, err := json.Marshal(jsonStruct)
if err != nil {
return err
}
fmt.Printf("%s\n", marshal) // => {}
Maintenance
v0.5.0
v0.4.0
What's Changed
New Features
Support FlatMap functions: #10 (@moznion)
This version begins to support the following new methods:
FlatMap[T, U any](option Option[T], mapper func(v T) Option[U]) Option[U]
FlatMapOr[T, U any](option Option[T], fallbackValue U, mapper func(v T) Option[U]) U
FlatMapWithError[T, U any](option Option[T], mapper func(v T) (Option[U], error)) (Option[U], error)
FlatMapOrWithError[T, U any](option Option[T], fallbackValue U, mapper func(v T) (Option[U], error)) (U, error)
Please refer to the godoc for more details: https://pkg.go.dev/github.com/moznion/go-optional