Go Optional Versions Save

A library that provides Go Generics friendly "optional" features.

v0.11.0

9 months ago

New Features

  • Implements database/sql/driver.Valuer and database/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

1 year ago

New Feature with Breaking Change

Support "correct" #OrElse() function #22

This feature changes the method signature of the #OrElse() that was introduced by v0.9.0, becoming to take a function that provides the fallback optional value. And the old implementation has been renamed #Or().

v0.9.0

1 year ago

New Features

v0.8.0

1 year ago

New Features

  • Support Stringer interface on Optional[T] #19

v0.7.0

1 year ago

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

1 year ago

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

  • Add go1.19 checking in GitHub Actions #15
  • Update module github.com/stretchr/testify to v1.8.1 #16

v0.5.0

1 year ago

What's Changed

New Features

  • Support JSON marshal and unmarshal for Option[T] value #13

Documents

  • Tweak the grammatical items in godoc #14

Dependencies

  • Update module go to 1.19 #12
  • Update module github.com/stretchr/testify to v1.8.0 #11

v0.4.0

1 year ago

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

v0.3.0

1 year ago

What's Changed

New Features

  • Support Option[T]#Unwrap() method #9 (@moznion)

v0.2.0

1 year ago

What's Changed

New Features

Add new If* method onto Option struct #8 (@moznion)

This version begins to support the following new methods:

  • func (o Option[T]) IfSome(f func(v T))
  • func (o Option[T]) IfSomeWithError(f func(v T) error) error
  • func (o Option[T]) IfNone(f func())
  • func (o Option[T]) IfNoneWithError(f func() error) erro

Please refer to the godoc for more details: https://pkg.go.dev/github.com/moznion/go-optional

Maintenance

Update module github.com/stretchr/testify to v1.7.2 #7 (@moznion)