File tree Expand file tree Collapse file tree 2 files changed +14
-14
lines changed Expand file tree Collapse file tree 2 files changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -34,10 +34,10 @@ func (o Option[T]) IsNone() bool {
3434
3535// Unwrap returns the values if the option is not empty or panics.
3636func (o Option [T ]) Unwrap () T {
37- if o .IsNone () {
38- panic ( "Option.Unwrap: option is None" )
37+ if o .isSome {
38+ return o . value
3939 }
40- return o . value
40+ panic ( "Option.Unwrap: option is None" )
4141}
4242
4343// Some creates a new Option with the given values.
@@ -52,10 +52,10 @@ func None[T any]() Option[T] {
5252
5353// MarshalJSON implements the json.Marshaler interface.
5454func (o Option [T ]) MarshalJSON () ([]byte , error ) {
55- if o .IsNone () {
56- return [] byte ( "null" ), nil
55+ if o .isSome {
56+ return json . Marshal ( o . value )
5757 }
58- return json . Marshal ( o . value )
58+ return [] byte ( "null" ), nil
5959}
6060
6161// UnmarshalJSON implements the json.Unmarshaler interface.
@@ -74,11 +74,11 @@ func (o *Option[T]) UnmarshalJSON(data []byte) error {
7474}
7575
7676// Value implements the driver.Valuer interface.
77- func (o * Option [T ]) Value () (driver.Value , error ) {
78- if o .IsNone () {
79- return nil , nil
77+ func (o Option [T ]) Value () (driver.Value , error ) {
78+ if o .isSome {
79+ return o . Unwrap () , nil
8080 }
81- return o . Unwrap () , nil
81+ return nil , nil
8282}
8383
8484// Scan implements the sql.Scanner interface.
Original file line number Diff line number Diff line change @@ -27,15 +27,15 @@ func (r Result[T, E]) IsOk() bool {
2727
2828// IsErr returns true if the result is not successful and has an error.
2929func (r Result [T , E ]) IsErr () bool {
30- return ! r .IsOk ()
30+ return ! r .isOk
3131}
3232
3333// Unwrap returns the values of the result. It panics if there is no result due to not checking for errors.
3434func (r Result [T , E ]) Unwrap () T {
35- if ! r .isOk {
36- panic ( "Result.Unwrap(): result is Err" )
35+ if r .isOk {
36+ return r . ok
3737 }
38- return r . ok
38+ panic ( "Result.Unwrap(): result is Err" )
3939}
4040
4141// Err returns the error of the result. To be used after calling IsOK()
You can’t perform that action at this time.
0 commit comments