Documentation ¶
Overview ¶
Example (And) ¶
package main import ( "fmt" "github.com/nvanbenschoten/optional" ) func main() { values := []optional.String{ optional.MakeString("foo"), optional.MakeString(""), optional.MakeString("bar"), {}, } for _, v := range values { v2 := optional.MakeString("other") v3 := v.And(v2) value, err := v3.GetOrErr() if err != nil { fmt.Println(err.Error()) } else { fmt.Println(value) } } }
Output: other other other value not present
Example (Get) ¶
package main import ( "fmt" "github.com/nvanbenschoten/optional" ) func main() { values := []optional.String{ optional.MakeString("foo"), optional.MakeString(""), optional.MakeString("bar"), {}, } for _, v := range values { value := func() (s string) { defer func() { if r := recover(); r != nil { s = "[panics]" } }() return v.Get() }() fmt.Println(value) } }
Output: foo bar [panics]
Example (GetOr) ¶
package main import ( "fmt" "github.com/nvanbenschoten/optional" ) func main() { values := []optional.String{ optional.MakeString("foo"), optional.MakeString(""), optional.MakeString("bar"), {}, } for _, v := range values { fmt.Println(v.GetOr("not present")) } }
Output: foo bar not present
Example (GetOrBool) ¶
package main import ( "fmt" "github.com/nvanbenschoten/optional" ) func main() { values := []optional.String{ optional.MakeString("foo"), optional.MakeString(""), optional.MakeString("bar"), {}, } for _, v := range values { if s, ok := v.GetOrBool(); ok { fmt.Println(s) } else { fmt.Println("not present") } } }
Output: foo bar not present
Example (GetOrErr) ¶
package main import ( "fmt" "github.com/nvanbenschoten/optional" ) func main() { values := []optional.String{ optional.MakeString("foo"), optional.MakeString(""), optional.MakeString("bar"), {}, } for _, v := range values { if s, err := v.GetOrErr(); err != nil { fmt.Println(err) } else { fmt.Println(s) } } }
Output: foo bar value not present
Example (If) ¶
package main import ( "fmt" "github.com/nvanbenschoten/optional" ) func main() { values := []optional.String{ optional.MakeString("foo"), optional.MakeString(""), optional.MakeString("bar"), {}, } for _, v := range values { v.If(func(s string) { fmt.Printf("called for %q\n", s) }) } }
Output: called for "foo" called for "" called for "bar"
Example (Map) ¶
package main import ( "fmt" "github.com/nvanbenschoten/optional" ) func main() { values := []optional.String{ optional.MakeString("foo"), optional.MakeString(""), optional.MakeString("bar"), {}, } for _, v := range values { v2 := v.Map(func(s string) string { return fmt.Sprintf("updated %q", s) }) value, err := v2.GetOrErr() if err != nil { fmt.Println(err.Error()) } else { fmt.Println(value) } } }
Output: updated "foo" updated "" updated "bar" value not present
Example (MarshalJSON) ¶
package main import ( "encoding/json" "fmt" "github.com/nvanbenschoten/optional" ) func main() { type example struct { Field *optional.String `json:"field,omitempty"` FieldTwo *optional.String `json:"field_two"` } var values = []optional.String{ optional.MakeString("foo"), optional.MakeString(""), optional.MakeString("bar"), } for _, v := range values { out, _ := json.Marshal(&example{ Field: &v, FieldTwo: &v, }) fmt.Println(string(out)) } out, _ := json.Marshal(&example{}) fmt.Println(string(out)) }
Output: {"field":"foo","field_two":"foo"} {"field":"","field_two":""} {"field":"bar","field_two":"bar"} {"field_two":null}
Example (Or) ¶
package main import ( "fmt" "github.com/nvanbenschoten/optional" ) func main() { values := []optional.String{ optional.MakeString("foo"), optional.MakeString(""), optional.MakeString("bar"), {}, } for _, v := range values { v2 := optional.MakeString("other") v3 := v.Or(v2) value, err := v3.GetOrErr() if err != nil { fmt.Println(err.Error()) } else { fmt.Println(value) } } }
Output: foo bar other
Example (Present) ¶
package main import ( "fmt" "github.com/nvanbenschoten/optional" ) func main() { values := []optional.String{ optional.MakeString("foo"), optional.MakeString(""), optional.MakeString("bar"), {}, } for _, v := range values { fmt.Println(v.Present()) } }
Output: true true true false
Example (Set) ¶
package main import ( "fmt" "github.com/nvanbenschoten/optional" ) func main() { var ( values = []string{ "foo", "", "bar", } s = optional.MakeString("baz") ) for _, v := range values { s.Set(v) value, err := s.GetOrErr() if err != nil { fmt.Println(err.Error()) } else { fmt.Println(value) } } }
Output: foo bar
Example (UnmarshalJSON) ¶
package main import ( "encoding/json" "fmt" "github.com/nvanbenschoten/optional" ) func main() { var values = []string{ `{"field":"foo","field_two":"foo"}`, `{"field":"","field_two":""}`, `{"field":"null","field_two":"null"}`, `{"field":"bar","field_two":"bar"}`, "{}", } for _, v := range values { var o = &struct { Field optional.String `json:"field,omitempty"` FieldTwo optional.String `json:"field_two"` }{} if err := json.Unmarshal([]byte(v), o); err != nil { fmt.Println(err) } o.Field.If(func(s string) { fmt.Println(s) }) o.FieldTwo.If(func(s string) { fmt.Println(s) }) }
Output:
Example (Unset) ¶
package main import ( "fmt" "github.com/nvanbenschoten/optional" ) func main() { values := []optional.String{ optional.MakeString("foo"), optional.MakeString(""), optional.MakeString("bar"), {}, } for _, v := range values { v.Unset() value, err := v.GetOrErr() if err != nil { fmt.Println(err.Error()) } else { fmt.Println(value) } } }
Output: value not present value not present value not present value not present
Index ¶
- type Bool
- func (b Bool) And(optb Bool) Bool
- func (b Bool) Get() bool
- func (b Bool) GetOr(v bool) bool
- func (b Bool) GetOrBool() (bool, bool)
- func (b Bool) GetOrErr() (bool, error)
- func (b Bool) If(fn func(bool))
- func (b Bool) Map(fn func(bool) bool) Bool
- func (b Bool) MarshalJSON() ([]byte, error)
- func (b Bool) Or(optb Bool) Bool
- func (b Bool) Present() bool
- func (b *Bool) Set(v bool)
- func (b *Bool) UnmarshalJSON(data []byte) error
- func (b *Bool) Unset()
- type Byte
- func (b Byte) And(optb Byte) Byte
- func (b Byte) Get() byte
- func (b Byte) GetOr(v byte) byte
- func (b Byte) GetOrBool() (byte, bool)
- func (b Byte) GetOrErr() (byte, error)
- func (b Byte) If(fn func(byte))
- func (b Byte) Map(fn func(byte) byte) Byte
- func (b Byte) MarshalJSON() ([]byte, error)
- func (b Byte) Or(optb Byte) Byte
- func (b Byte) Present() bool
- func (b *Byte) Set(v byte)
- func (b *Byte) UnmarshalJSON(data []byte) error
- func (b *Byte) Unset()
- type Complex128
- func (c Complex128) And(optb Complex128) Complex128
- func (c Complex128) Get() complex128
- func (c Complex128) GetOr(v complex128) complex128
- func (c Complex128) GetOrBool() (complex128, bool)
- func (c Complex128) GetOrErr() (complex128, error)
- func (c Complex128) If(fn func(complex128))
- func (c Complex128) Map(fn func(complex128) complex128) Complex128
- func (c Complex128) MarshalJSON() ([]byte, error)
- func (c Complex128) Or(optb Complex128) Complex128
- func (c Complex128) Present() bool
- func (c *Complex128) Set(v complex128)
- func (c *Complex128) UnmarshalJSON(data []byte) error
- func (c *Complex128) Unset()
- type Complex64
- func (c Complex64) And(optb Complex64) Complex64
- func (c Complex64) Get() complex64
- func (c Complex64) GetOr(v complex64) complex64
- func (c Complex64) GetOrBool() (complex64, bool)
- func (c Complex64) GetOrErr() (complex64, error)
- func (c Complex64) If(fn func(complex64))
- func (c Complex64) Map(fn func(complex64) complex64) Complex64
- func (c Complex64) MarshalJSON() ([]byte, error)
- func (c Complex64) Or(optb Complex64) Complex64
- func (c Complex64) Present() bool
- func (c *Complex64) Set(v complex64)
- func (c *Complex64) UnmarshalJSON(data []byte) error
- func (c *Complex64) Unset()
- type Error
- func (e Error) And(optb Error) Error
- func (e Error) Get() error
- func (e Error) GetOr(v error) error
- func (e Error) GetOrBool() (error, bool)
- func (e Error) GetOrErr() (error, error)
- func (e Error) If(fn func(error))
- func (e Error) Map(fn func(error) error) Error
- func (e Error) MarshalJSON() ([]byte, error)
- func (e Error) Or(optb Error) Error
- func (e Error) Present() bool
- func (e *Error) Set(v error)
- func (e *Error) UnmarshalJSON(data []byte) error
- func (e *Error) Unset()
- type Float32
- func (f Float32) And(optb Float32) Float32
- func (f Float32) Get() float32
- func (f Float32) GetOr(v float32) float32
- func (f Float32) GetOrBool() (float32, bool)
- func (f Float32) GetOrErr() (float32, error)
- func (f Float32) If(fn func(float32))
- func (f Float32) Map(fn func(float32) float32) Float32
- func (f Float32) MarshalJSON() ([]byte, error)
- func (f Float32) Or(optb Float32) Float32
- func (f Float32) Present() bool
- func (f *Float32) Set(v float32)
- func (f *Float32) UnmarshalJSON(data []byte) error
- func (f *Float32) Unset()
- type Float64
- func (f Float64) And(optb Float64) Float64
- func (f Float64) Get() float64
- func (f Float64) GetOr(v float64) float64
- func (f Float64) GetOrBool() (float64, bool)
- func (f Float64) GetOrErr() (float64, error)
- func (f Float64) If(fn func(float64))
- func (f Float64) Map(fn func(float64) float64) Float64
- func (f Float64) MarshalJSON() ([]byte, error)
- func (f Float64) Or(optb Float64) Float64
- func (f Float64) Present() bool
- func (f *Float64) Set(v float64)
- func (f *Float64) UnmarshalJSON(data []byte) error
- func (f *Float64) Unset()
- type Int
- func (i Int) And(optb Int) Int
- func (i Int) Get() int
- func (i Int) GetOr(v int) int
- func (i Int) GetOrBool() (int, bool)
- func (i Int) GetOrErr() (int, error)
- func (i Int) If(fn func(int))
- func (i Int) Map(fn func(int) int) Int
- func (i Int) MarshalJSON() ([]byte, error)
- func (i Int) Or(optb Int) Int
- func (i Int) Present() bool
- func (i *Int) Set(v int)
- func (i *Int) UnmarshalJSON(data []byte) error
- func (i *Int) Unset()
- type Int16
- func (i Int16) And(optb Int16) Int16
- func (i Int16) Get() int16
- func (i Int16) GetOr(v int16) int16
- func (i Int16) GetOrBool() (int16, bool)
- func (i Int16) GetOrErr() (int16, error)
- func (i Int16) If(fn func(int16))
- func (i Int16) Map(fn func(int16) int16) Int16
- func (i Int16) MarshalJSON() ([]byte, error)
- func (i Int16) Or(optb Int16) Int16
- func (i Int16) Present() bool
- func (i *Int16) Set(v int16)
- func (i *Int16) UnmarshalJSON(data []byte) error
- func (i *Int16) Unset()
- type Int32
- func (i Int32) And(optb Int32) Int32
- func (i Int32) Get() int32
- func (i Int32) GetOr(v int32) int32
- func (i Int32) GetOrBool() (int32, bool)
- func (i Int32) GetOrErr() (int32, error)
- func (i Int32) If(fn func(int32))
- func (i Int32) Map(fn func(int32) int32) Int32
- func (i Int32) MarshalJSON() ([]byte, error)
- func (i Int32) Or(optb Int32) Int32
- func (i Int32) Present() bool
- func (i *Int32) Set(v int32)
- func (i *Int32) UnmarshalJSON(data []byte) error
- func (i *Int32) Unset()
- type Int64
- func (i Int64) And(optb Int64) Int64
- func (i Int64) Get() int64
- func (i Int64) GetOr(v int64) int64
- func (i Int64) GetOrBool() (int64, bool)
- func (i Int64) GetOrErr() (int64, error)
- func (i Int64) If(fn func(int64))
- func (i Int64) Map(fn func(int64) int64) Int64
- func (i Int64) MarshalJSON() ([]byte, error)
- func (i Int64) Or(optb Int64) Int64
- func (i Int64) Present() bool
- func (i *Int64) Set(v int64)
- func (i *Int64) UnmarshalJSON(data []byte) error
- func (i *Int64) Unset()
- type Int8
- func (i Int8) And(optb Int8) Int8
- func (i Int8) Get() int8
- func (i Int8) GetOr(v int8) int8
- func (i Int8) GetOrBool() (int8, bool)
- func (i Int8) GetOrErr() (int8, error)
- func (i Int8) If(fn func(int8))
- func (i Int8) Map(fn func(int8) int8) Int8
- func (i Int8) MarshalJSON() ([]byte, error)
- func (i Int8) Or(optb Int8) Int8
- func (i Int8) Present() bool
- func (i *Int8) Set(v int8)
- func (i *Int8) UnmarshalJSON(data []byte) error
- func (i *Int8) Unset()
- type Rune
- func (r Rune) And(optb Rune) Rune
- func (r Rune) Get() rune
- func (r Rune) GetOr(v rune) rune
- func (r Rune) GetOrBool() (rune, bool)
- func (r Rune) GetOrErr() (rune, error)
- func (r Rune) If(fn func(rune))
- func (r Rune) Map(fn func(rune) rune) Rune
- func (r Rune) MarshalJSON() ([]byte, error)
- func (r Rune) Or(optb Rune) Rune
- func (r Rune) Present() bool
- func (r *Rune) Set(v rune)
- func (r *Rune) UnmarshalJSON(data []byte) error
- func (r *Rune) Unset()
- type String
- func (s String) And(optb String) String
- func (s String) Get() string
- func (s String) GetOr(v string) string
- func (s String) GetOrBool() (string, bool)
- func (s String) GetOrErr() (string, error)
- func (s String) If(fn func(string))
- func (s String) Map(fn func(string) string) String
- func (s String) MarshalJSON() ([]byte, error)
- func (s String) Or(optb String) String
- func (s String) Present() bool
- func (s *String) Set(v string)
- func (s *String) UnmarshalJSON(data []byte) error
- func (s *String) Unset()
- type Uint
- func (u Uint) And(optb Uint) Uint
- func (u Uint) Get() uint
- func (u Uint) GetOr(v uint) uint
- func (u Uint) GetOrBool() (uint, bool)
- func (u Uint) GetOrErr() (uint, error)
- func (u Uint) If(fn func(uint))
- func (u Uint) Map(fn func(uint) uint) Uint
- func (u Uint) MarshalJSON() ([]byte, error)
- func (u Uint) Or(optb Uint) Uint
- func (u Uint) Present() bool
- func (u *Uint) Set(v uint)
- func (u *Uint) UnmarshalJSON(data []byte) error
- func (u *Uint) Unset()
- type Uint16
- func (u Uint16) And(optb Uint16) Uint16
- func (u Uint16) Get() uint16
- func (u Uint16) GetOr(v uint16) uint16
- func (u Uint16) GetOrBool() (uint16, bool)
- func (u Uint16) GetOrErr() (uint16, error)
- func (u Uint16) If(fn func(uint16))
- func (u Uint16) Map(fn func(uint16) uint16) Uint16
- func (u Uint16) MarshalJSON() ([]byte, error)
- func (u Uint16) Or(optb Uint16) Uint16
- func (u Uint16) Present() bool
- func (u *Uint16) Set(v uint16)
- func (u *Uint16) UnmarshalJSON(data []byte) error
- func (u *Uint16) Unset()
- type Uint32
- func (u Uint32) And(optb Uint32) Uint32
- func (u Uint32) Get() uint32
- func (u Uint32) GetOr(v uint32) uint32
- func (u Uint32) GetOrBool() (uint32, bool)
- func (u Uint32) GetOrErr() (uint32, error)
- func (u Uint32) If(fn func(uint32))
- func (u Uint32) Map(fn func(uint32) uint32) Uint32
- func (u Uint32) MarshalJSON() ([]byte, error)
- func (u Uint32) Or(optb Uint32) Uint32
- func (u Uint32) Present() bool
- func (u *Uint32) Set(v uint32)
- func (u *Uint32) UnmarshalJSON(data []byte) error
- func (u *Uint32) Unset()
- type Uint64
- func (u Uint64) And(optb Uint64) Uint64
- func (u Uint64) Get() uint64
- func (u Uint64) GetOr(v uint64) uint64
- func (u Uint64) GetOrBool() (uint64, bool)
- func (u Uint64) GetOrErr() (uint64, error)
- func (u Uint64) If(fn func(uint64))
- func (u Uint64) Map(fn func(uint64) uint64) Uint64
- func (u Uint64) MarshalJSON() ([]byte, error)
- func (u Uint64) Or(optb Uint64) Uint64
- func (u Uint64) Present() bool
- func (u *Uint64) Set(v uint64)
- func (u *Uint64) UnmarshalJSON(data []byte) error
- func (u *Uint64) Unset()
- type Uint8
- func (u Uint8) And(optb Uint8) Uint8
- func (u Uint8) Get() uint8
- func (u Uint8) GetOr(v uint8) uint8
- func (u Uint8) GetOrBool() (uint8, bool)
- func (u Uint8) GetOrErr() (uint8, error)
- func (u Uint8) If(fn func(uint8))
- func (u Uint8) Map(fn func(uint8) uint8) Uint8
- func (u Uint8) MarshalJSON() ([]byte, error)
- func (u Uint8) Or(optb Uint8) Uint8
- func (u Uint8) Present() bool
- func (u *Uint8) Set(v uint8)
- func (u *Uint8) UnmarshalJSON(data []byte) error
- func (u *Uint8) Unset()
- type Uintptr
- func (u Uintptr) And(optb Uintptr) Uintptr
- func (u Uintptr) Get() uintptr
- func (u Uintptr) GetOr(v uintptr) uintptr
- func (u Uintptr) GetOrBool() (uintptr, bool)
- func (u Uintptr) GetOrErr() (uintptr, error)
- func (u Uintptr) If(fn func(uintptr))
- func (u Uintptr) Map(fn func(uintptr) uintptr) Uintptr
- func (u Uintptr) MarshalJSON() ([]byte, error)
- func (u Uintptr) Or(optb Uintptr) Uintptr
- func (u Uintptr) Present() bool
- func (u *Uintptr) Set(v uintptr)
- func (u *Uintptr) UnmarshalJSON(data []byte) error
- func (u *Uintptr) Unset()
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bool ¶
type Bool struct {
// contains filtered or unexported fields
}
Bool is an optional bool.
func (Bool) And ¶ added in v0.8.1
And returns an empty Bool option value if not present, otherwise returns optb.
func (Bool) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Bool) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Bool) Or ¶ added in v0.8.1
Or returns the Bool option value if present, otherwise returns optb.
func (*Bool) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Byte ¶
type Byte struct {
// contains filtered or unexported fields
}
Byte is an optional byte.
func (Byte) And ¶ added in v0.8.1
And returns an empty Byte option value if not present, otherwise returns optb.
func (Byte) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Byte) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Byte) Or ¶ added in v0.8.1
Or returns the Byte option value if present, otherwise returns optb.
func (*Byte) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Complex128 ¶
type Complex128 struct {
// contains filtered or unexported fields
}
Complex128 is an optional complex128.
func MakeComplex128 ¶ added in v0.8.0
func MakeComplex128(v complex128) Complex128
MakeComplex128 creates an optional.Complex128 from a complex128.
func (Complex128) And ¶ added in v0.8.1
func (c Complex128) And(optb Complex128) Complex128
And returns an empty Complex128 option value if not present, otherwise returns optb.
func (Complex128) Get ¶
func (c Complex128) Get() complex128
Get returns the complex128 value or panics if not present.
func (Complex128) GetOr ¶ added in v0.8.1
func (c Complex128) GetOr(v complex128) complex128
GetOr returns the complex128 value or a default value if not present.
func (Complex128) GetOrBool ¶ added in v0.8.2
func (c Complex128) GetOrBool() (complex128, bool)
GetOrBool returns the complex128 value or false if not present.
func (Complex128) GetOrErr ¶ added in v0.8.1
func (c Complex128) GetOrErr() (complex128, error)
GetOrErr returns the complex128 value or an error if not present.
func (Complex128) If ¶ added in v0.2.0
func (c Complex128) If(fn func(complex128))
If calls the function fn with the value if the value is present.
func (Complex128) Map ¶ added in v0.8.1
func (c Complex128) Map(fn func(complex128) complex128) Complex128
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Complex128) MarshalJSON ¶ added in v0.4.0
func (c Complex128) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (Complex128) Or ¶ added in v0.8.1
func (c Complex128) Or(optb Complex128) Complex128
Or returns the Complex128 option value if present, otherwise returns optb.
func (Complex128) Present ¶
func (c Complex128) Present() bool
Present returns whether or not the value is present.
func (*Complex128) UnmarshalJSON ¶ added in v0.4.0
func (c *Complex128) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Complex128) Unset ¶ added in v0.8.0
func (c *Complex128) Unset()
Unset unsets the complex128 value.
type Complex64 ¶
type Complex64 struct {
// contains filtered or unexported fields
}
Complex64 is an optional complex64.
func MakeComplex64 ¶ added in v0.8.0
MakeComplex64 creates an optional.Complex64 from a complex64.
func (Complex64) And ¶ added in v0.8.1
And returns an empty Complex64 option value if not present, otherwise returns optb.
func (Complex64) GetOr ¶ added in v0.8.1
GetOr returns the complex64 value or a default value if not present.
func (Complex64) GetOrBool ¶ added in v0.8.2
GetOrBool returns the complex64 value or false if not present.
func (Complex64) GetOrErr ¶ added in v0.8.1
GetOrErr returns the complex64 value or an error if not present.
func (Complex64) If ¶ added in v0.2.0
If calls the function fn with the value if the value is present.
func (Complex64) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Complex64) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Complex64) Or ¶ added in v0.8.1
Or returns the Complex64 option value if present, otherwise returns optb.
func (*Complex64) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is an optional error.
func (Error) And ¶ added in v0.8.1
And returns an empty Error option value if not present, otherwise returns optb.
func (Error) GetOr ¶ added in v0.8.1
GetOr returns the error value or a default value if not present.
func (Error) GetOrErr ¶ added in v0.8.1
GetOrErr returns the error value or an error if not present.
func (Error) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Error) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Error) Or ¶ added in v0.8.1
Or returns the Error option value if present, otherwise returns optb.
func (*Error) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Float32 ¶
type Float32 struct {
// contains filtered or unexported fields
}
Float32 is an optional float32.
func MakeFloat32 ¶ added in v0.8.0
MakeFloat32 creates an optional.Float32 from a float32.
func (Float32) And ¶ added in v0.8.1
And returns an empty Float32 option value if not present, otherwise returns optb.
func (Float32) GetOr ¶ added in v0.8.1
GetOr returns the float32 value or a default value if not present.
func (Float32) GetOrBool ¶ added in v0.8.2
GetOrBool returns the float32 value or false if not present.
func (Float32) GetOrErr ¶ added in v0.8.1
GetOrErr returns the float32 value or an error if not present.
func (Float32) If ¶ added in v0.2.0
If calls the function fn with the value if the value is present.
func (Float32) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Float32) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Float32) Or ¶ added in v0.8.1
Or returns the Float32 option value if present, otherwise returns optb.
func (*Float32) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Float64 ¶
type Float64 struct {
// contains filtered or unexported fields
}
Float64 is an optional float64.
func MakeFloat64 ¶ added in v0.8.0
MakeFloat64 creates an optional.Float64 from a float64.
func (Float64) And ¶ added in v0.8.1
And returns an empty Float64 option value if not present, otherwise returns optb.
func (Float64) GetOr ¶ added in v0.8.1
GetOr returns the float64 value or a default value if not present.
func (Float64) GetOrBool ¶ added in v0.8.2
GetOrBool returns the float64 value or false if not present.
func (Float64) GetOrErr ¶ added in v0.8.1
GetOrErr returns the float64 value or an error if not present.
func (Float64) If ¶ added in v0.2.0
If calls the function fn with the value if the value is present.
func (Float64) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Float64) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Float64) Or ¶ added in v0.8.1
Or returns the Float64 option value if present, otherwise returns optb.
func (*Float64) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Int ¶
type Int struct {
// contains filtered or unexported fields
}
Int is an optional int.
func (Int) And ¶ added in v0.8.1
And returns an empty Int option value if not present, otherwise returns optb.
func (Int) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Int) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (*Int) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Int16 ¶
type Int16 struct {
// contains filtered or unexported fields
}
Int16 is an optional int16.
func (Int16) And ¶ added in v0.8.1
And returns an empty Int16 option value if not present, otherwise returns optb.
func (Int16) GetOr ¶ added in v0.8.1
GetOr returns the int16 value or a default value if not present.
func (Int16) GetOrErr ¶ added in v0.8.1
GetOrErr returns the int16 value or an error if not present.
func (Int16) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Int16) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Int16) Or ¶ added in v0.8.1
Or returns the Int16 option value if present, otherwise returns optb.
func (*Int16) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Int32 ¶
type Int32 struct {
// contains filtered or unexported fields
}
Int32 is an optional int32.
func (Int32) And ¶ added in v0.8.1
And returns an empty Int32 option value if not present, otherwise returns optb.
func (Int32) GetOr ¶ added in v0.8.1
GetOr returns the int32 value or a default value if not present.
func (Int32) GetOrErr ¶ added in v0.8.1
GetOrErr returns the int32 value or an error if not present.
func (Int32) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Int32) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Int32) Or ¶ added in v0.8.1
Or returns the Int32 option value if present, otherwise returns optb.
func (*Int32) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Int64 ¶
type Int64 struct {
// contains filtered or unexported fields
}
Int64 is an optional int64.
func (Int64) And ¶ added in v0.8.1
And returns an empty Int64 option value if not present, otherwise returns optb.
func (Int64) GetOr ¶ added in v0.8.1
GetOr returns the int64 value or a default value if not present.
func (Int64) GetOrErr ¶ added in v0.8.1
GetOrErr returns the int64 value or an error if not present.
func (Int64) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Int64) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Int64) Or ¶ added in v0.8.1
Or returns the Int64 option value if present, otherwise returns optb.
func (*Int64) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Int8 ¶
type Int8 struct {
// contains filtered or unexported fields
}
Int8 is an optional int8.
func (Int8) And ¶ added in v0.8.1
And returns an empty Int8 option value if not present, otherwise returns optb.
func (Int8) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Int8) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Int8) Or ¶ added in v0.8.1
Or returns the Int8 option value if present, otherwise returns optb.
func (*Int8) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Rune ¶
type Rune struct {
// contains filtered or unexported fields
}
Rune is an optional rune.
func (Rune) And ¶ added in v0.8.1
And returns an empty Rune option value if not present, otherwise returns optb.
func (Rune) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Rune) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Rune) Or ¶ added in v0.8.1
Or returns the Rune option value if present, otherwise returns optb.
func (*Rune) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type String ¶
type String struct {
// contains filtered or unexported fields
}
String is an optional string.
func MakeString ¶ added in v0.8.0
MakeString creates an optional.String from a string.
func (String) And ¶ added in v0.8.1
And returns an empty String option value if not present, otherwise returns optb.
func (String) GetOr ¶ added in v0.8.1
GetOr returns the string value or a default value if not present.
func (String) GetOrBool ¶ added in v0.8.2
GetOrBool returns the string value or false if not present.
func (String) GetOrErr ¶ added in v0.8.1
GetOrErr returns the string value or an error if not present.
func (String) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (String) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (String) Or ¶ added in v0.8.1
Or returns the String option value if present, otherwise returns optb.
func (*String) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Uint ¶
type Uint struct {
// contains filtered or unexported fields
}
Uint is an optional uint.
func (Uint) And ¶ added in v0.8.1
And returns an empty Uint option value if not present, otherwise returns optb.
func (Uint) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Uint) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Uint) Or ¶ added in v0.8.1
Or returns the Uint option value if present, otherwise returns optb.
func (*Uint) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Uint16 ¶
type Uint16 struct {
// contains filtered or unexported fields
}
Uint16 is an optional uint16.
func MakeUint16 ¶ added in v0.8.0
MakeUint16 creates an optional.Uint16 from a uint16.
func (Uint16) And ¶ added in v0.8.1
And returns an empty Uint16 option value if not present, otherwise returns optb.
func (Uint16) GetOr ¶ added in v0.8.1
GetOr returns the uint16 value or a default value if not present.
func (Uint16) GetOrBool ¶ added in v0.8.2
GetOrBool returns the uint16 value or false if not present.
func (Uint16) GetOrErr ¶ added in v0.8.1
GetOrErr returns the uint16 value or an error if not present.
func (Uint16) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Uint16) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Uint16) Or ¶ added in v0.8.1
Or returns the Uint16 option value if present, otherwise returns optb.
func (*Uint16) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Uint32 ¶
type Uint32 struct {
// contains filtered or unexported fields
}
Uint32 is an optional uint32.
func MakeUint32 ¶ added in v0.8.0
MakeUint32 creates an optional.Uint32 from a uint32.
func (Uint32) And ¶ added in v0.8.1
And returns an empty Uint32 option value if not present, otherwise returns optb.
func (Uint32) GetOr ¶ added in v0.8.1
GetOr returns the uint32 value or a default value if not present.
func (Uint32) GetOrBool ¶ added in v0.8.2
GetOrBool returns the uint32 value or false if not present.
func (Uint32) GetOrErr ¶ added in v0.8.1
GetOrErr returns the uint32 value or an error if not present.
func (Uint32) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Uint32) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Uint32) Or ¶ added in v0.8.1
Or returns the Uint32 option value if present, otherwise returns optb.
func (*Uint32) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Uint64 ¶
type Uint64 struct {
// contains filtered or unexported fields
}
Uint64 is an optional uint64.
func MakeUint64 ¶ added in v0.8.0
MakeUint64 creates an optional.Uint64 from a uint64.
func (Uint64) And ¶ added in v0.8.1
And returns an empty Uint64 option value if not present, otherwise returns optb.
func (Uint64) GetOr ¶ added in v0.8.1
GetOr returns the uint64 value or a default value if not present.
func (Uint64) GetOrBool ¶ added in v0.8.2
GetOrBool returns the uint64 value or false if not present.
func (Uint64) GetOrErr ¶ added in v0.8.1
GetOrErr returns the uint64 value or an error if not present.
func (Uint64) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Uint64) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Uint64) Or ¶ added in v0.8.1
Or returns the Uint64 option value if present, otherwise returns optb.
func (*Uint64) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Uint8 ¶
type Uint8 struct {
// contains filtered or unexported fields
}
Uint8 is an optional uint8.
func (Uint8) And ¶ added in v0.8.1
And returns an empty Uint8 option value if not present, otherwise returns optb.
func (Uint8) GetOr ¶ added in v0.8.1
GetOr returns the uint8 value or a default value if not present.
func (Uint8) GetOrErr ¶ added in v0.8.1
GetOrErr returns the uint8 value or an error if not present.
func (Uint8) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Uint8) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Uint8) Or ¶ added in v0.8.1
Or returns the Uint8 option value if present, otherwise returns optb.
func (*Uint8) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
type Uintptr ¶
type Uintptr struct {
// contains filtered or unexported fields
}
Uintptr is an optional uintptr.
func MakeUintptr ¶ added in v0.8.0
MakeUintptr creates an optional.Uintptr from a uintptr.
func (Uintptr) And ¶ added in v0.8.1
And returns an empty Uintptr option value if not present, otherwise returns optb.
func (Uintptr) GetOr ¶ added in v0.8.1
GetOr returns the uintptr value or a default value if not present.
func (Uintptr) GetOrBool ¶ added in v0.8.2
GetOrBool returns the uintptr value or false if not present.
func (Uintptr) GetOrErr ¶ added in v0.8.1
GetOrErr returns the uintptr value or an error if not present.
func (Uintptr) If ¶ added in v0.2.0
If calls the function fn with the value if the value is present.
func (Uintptr) Map ¶ added in v0.8.1
Map applies the function fn to the contained value (if any) and returns a new option value.
func (Uintptr) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface.
func (Uintptr) Or ¶ added in v0.8.1
Or returns the Uintptr option value if present, otherwise returns optb.
func (*Uintptr) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
optional
Optional is a tool that generates 'optional' type wrappers around a given type T. Typically this process would be run using go generate, like this: //go:generate optional -type=Foo running this command optional -type=Foo in the same directory will create the file optional_foo.go containing a definition of type OptionalFoo struct { ...
|
Optional is a tool that generates 'optional' type wrappers around a given type T. Typically this process would be run using go generate, like this: //go:generate optional -type=Foo running this command optional -type=Foo in the same directory will create the file optional_foo.go containing a definition of type OptionalFoo struct { ... |