Documentation
¶
Index ¶
- type Nullable
- func (receiver Nullable) Else(value string) Nullable
- func (receiver Nullable) ElseUnwrap(value string) string
- func (receiver Nullable) GoString() string
- func (receiver Nullable) Map(fn func(string) string) Nullable
- func (receiver Nullable) MarshalJSON() ([]byte, error)
- func (receiver Nullable) Return() (string, error)
- func (receiver Nullable) Then(fn func(string) Nullable) Nullable
- func (receiver *Nullable) UnmarshalJSON(data []byte) error
- func (receiver Nullable) Unwrap() (string, bool)
- func (receiver Nullable) Value() (driver.Value, error)
- type Option
- func (receiver Option) Else(value string) Option
- func (receiver Option) ElseUnwrap(value string) string
- func (receiver Option) GoString() string
- func (receiver Option) Map(fn func(string) string) Option
- func (receiver Option) MarshalJSON() ([]byte, error)
- func (receiver Option) Nullable() Nullable
- func (receiver Option) Return() (string, error)
- func (receiver Option) Then(fn func(string) Option) Option
- func (receiver *Option) UnmarshalJSON(data []byte) error
- func (receiver Option) Unwrap() (string, bool)
- func (receiver Option) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Nullable ¶
type Nullable struct {
// contains filtered or unexported fields
}
func (Nullable) Else ¶
Else defaults this ‘streng.Nullable’ to ‘value’ if this ‘streng.Nullable’ has a value of ‘streng.Nothing().Nullable()’, or a value of ‘streng.Null()’, else it just returns itself as is.
func (Nullable) ElseUnwrap ¶
func (Nullable) Map ¶
Map returns an ‘streng.Nullable’ containing the result of ‘fn’ applied to the value inside this ‘streng.Nullable’; if this ‘streng.Nullable’ is ‘streng.Nothing().Nullable()’, then it just returns ‘streng.Nothing()’; or if this ‘streng.Nullable’ is ‘streng.Null()’, then it just returns ‘streng.Null()’;
func (Nullable) MarshalJSON ¶
func (Nullable) Then ¶
Then returns an ‘streng.Nullable’ containing the result of ‘fn’ applied to the value inside this ‘streng.Nullable’; if this ‘streng.Nullable’ is ‘streng.Nothing().Nullable()’, then it just returns ‘streng.Nothing()’; and if this ‘streng.Nullable’ is ‘streng.Null()’, then it just returns ‘streng.Null()’.
func (*Nullable) UnmarshalJSON ¶
UnmarshalJSON makes streng.Nullable fit the json.Unmarshaler interface.
Note that streng.Nullable.UnmarshalJSON() also accepts JSON numbers, and not just JSON strings.
So if we have:
type Purchase struct { Amount streng.Nullable `json:"amount"` }
It accepts this JSON with a string literal:
{ "amount": "1.23" }
But it also accepts this JSON with a number literal:
{ "amount": 1.23 }
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option is an ‘option type’ for string.
It can contain:
• ‘nothing’, or
• ‘something’.
Nothing ¶
An uninitialize variable, of type ‘streng.Option’, contains ‘nothing’. I.e.,:...
var option streng.Option
You can determine if a variable of type ‘streng.Option’ contains ‘nothing’, or not, by using the ‘streng.Nothing()’ function.
For example:
if streng.Nothing() == option { //@TODO }
Or:
switch option { case streng.Nothing(): //@TODO default: //@TODO }
You can also use the ‘streng.Nothing()’ function to give a variable of type ‘streng.Option’ the value of nothing ‘nothing’:
option = streng.Nothing()
Something ¶
You can create a ‘streng.Option’ with ‘streng.Something()’. For example:
var option streng.Option = streng.Something("Hello world!")
func (Option) Else ¶
Else defaults this ‘streng.Option’ to ‘value’ if this ‘streng.Option’ has a value of ‘streng.Nothing()’, else it just returns itself as is.
func (Option) ElseUnwrap ¶
func (Option) Map ¶
Map returns an ‘streng.Option’ containing the result of ‘fn’ applied to the value inside this ‘streng.Option’; if this ‘streng.Option’ is ‘streng.Nothing()’, then it just returns ‘streng.Nothing()’.
func (Option) MarshalJSON ¶
func (Option) Nullable ¶
Nullable returns the equivalent ‘streng.Nullable’ for this ‘streng.Option’.
func (Option) Then ¶
Then returns an ‘streng.Option’ containing the result of ‘fn’ applied to the value inside this ‘streng.Option’; if this ‘streng.Option’ is ‘streng.Nothing()’, then it just returns ‘streng.Nothing()’.