Skip to content

Releases: moznion/go-optional

v0.12.0

05 Jun 01:27
7f202ad
Compare
Choose a tag to compare

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 for database/sql.convertAssign #33 @moznion

Bug Fixes

Maintenance

v0.11.0

22 Jul 06:23
894f328
Compare
Choose a tag to compare

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

08 Dec 05:43
e517051
Compare
Choose a tag to compare

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

07 Dec 18:39
54d6aaa
Compare
Choose a tag to compare

New Features

v0.8.0

16 Nov 01:39
c4d60f5
Compare
Choose a tag to compare

New Features

  • Support Stringer interface on Optional[T] #19

v0.7.0

12 Nov 00:39
610af3c
Compare
Choose a tag to compare

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

09 Nov 08:58
c8062ba
Compare
Choose a tag to compare

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

05 Sep 03:44
bb689e3
Compare
Choose a tag to compare

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

13 Jun 08:04
9157830
Compare
Choose a tag to compare

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

11 Jun 05:21
45dd457
Compare
Choose a tag to compare

What's Changed

New Features