Documentation ¶
Overview ¶
Example (Get) ¶
package main import ( "fmt" "github.com/markphelps/optional" ) func main() { values := []optional.String{ optional.OfString("foo"), optional.OfString(""), optional.OfString("bar"), optional.EmptyString(), } for _, v := range values { if v.Present() { fmt.Println(v.Get()) } } }
Output: foo bar
Example (If) ¶
package main import ( "fmt" "github.com/markphelps/optional" ) func main() { values := []optional.String{ optional.OfString("foo"), optional.OfString(""), optional.OfString("bar"), optional.EmptyString(), } for _, v := range values { v.If(func(s string) { fmt.Println("present") }) } }
Output: present present present
Example (OrElse) ¶
package main import ( "fmt" "github.com/markphelps/optional" ) func main() { values := []optional.String{ optional.OfString("foo"), optional.OfString(""), optional.OfString("bar"), optional.EmptyString(), } for _, v := range values { fmt.Println(v.OrElse("not present")) } }
Output: foo bar not present
Index ¶
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
type Byte ¶
type Byte struct {
// contains filtered or unexported fields
}
Byte is an optional byte
type Complex128 ¶
type Complex128 struct {
// contains filtered or unexported fields
}
Complex128 is an optional complex128
func EmptyComplex128 ¶
func EmptyComplex128() Complex128
EmptyComplex128 returns an empty optional.Complex128
func OfComplex128 ¶
func OfComplex128(c complex128) Complex128
OfComplex128 creates a optional.Complex128 from a complex128
func (*Complex128) If ¶ added in v0.2.0
func (o *Complex128) If(f func(c complex128))
If calls the function f with the value if the value is present
func (*Complex128) OrElse ¶
func (o *Complex128) OrElse(c complex128) complex128
OrElse returns the complex128 value or a default value if the value is not present
func (*Complex128) Present ¶
func (o *Complex128) Present() bool
Present returns whether or not the value is present
type Complex64 ¶
type Complex64 struct {
// contains filtered or unexported fields
}
Complex64 is an optional complex64
func EmptyComplex64 ¶
func EmptyComplex64() Complex64
EmptyComplex64 returns an empty optional.Complex64
func OfComplex64 ¶
OfComplex64 creates a optional.Complex64 from a complex64
func (*Complex64) If ¶ added in v0.2.0
If calls the function f with the value if the value is present
func (*Complex64) OrElse ¶
OrElse returns the complex64 value or a default value if the value is not present
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is an optional error
func (*Error) OrElse ¶
OrElse returns the error value or a default value if the value is not present
type Float32 ¶
type Float32 struct {
// contains filtered or unexported fields
}
Float32 is an optional float32
func (*Float32) OrElse ¶
OrElse returns the float32 value or a default value if the value is not present
type Float64 ¶
type Float64 struct {
// contains filtered or unexported fields
}
Float64 is an optional float64
func (*Float64) OrElse ¶
OrElse returns the float64 value or a default value if the value is not present
type Int ¶
type Int struct {
// contains filtered or unexported fields
}
Int is an optional int
type Int16 ¶
type Int16 struct {
// contains filtered or unexported fields
}
Int16 is an optional int16
func (*Int16) OrElse ¶
OrElse returns the int16 value or a default value if the value is not present
type Int32 ¶
type Int32 struct {
// contains filtered or unexported fields
}
Int32 is an optional int32
func (*Int32) OrElse ¶
OrElse returns the int32 value or a default value if the value is not present
type Int64 ¶
type Int64 struct {
// contains filtered or unexported fields
}
Int64 is an optional int64
func (*Int64) OrElse ¶
OrElse returns the int64 value or a default value if the value is not present
type Int8 ¶
type Int8 struct {
// contains filtered or unexported fields
}
Int8 is an optional int8
type Rune ¶
type Rune struct {
// contains filtered or unexported fields
}
Rune is an optional rune
type String ¶
type String struct {
// contains filtered or unexported fields
}
String is an optional string
func (*String) OrElse ¶
OrElse returns the string value or a default value if the value is not present
type Uint ¶
type Uint struct {
// contains filtered or unexported fields
}
Uint is an optional uint
type Uint16 ¶
type Uint16 struct {
// contains filtered or unexported fields
}
Uint16 is an optional uint16
func (*Uint16) OrElse ¶
OrElse returns the uint16 value or a default value if the value is not present
type Uint32 ¶
type Uint32 struct {
// contains filtered or unexported fields
}
Uint32 is an optional uint32
func (*Uint32) OrElse ¶
OrElse returns the uint32 value or a default value if the value is not present
type Uint64 ¶
type Uint64 struct {
// contains filtered or unexported fields
}
Uint64 is an optional uint64
func (*Uint64) OrElse ¶
OrElse returns the uint64 value or a default value if the value is not present
type Uint8 ¶
type Uint8 struct {
// contains filtered or unexported fields
}
Uint8 is an optional uint8
func (*Uint8) OrElse ¶
OrElse returns the uint8 value or a default value if the value is not present
type Uintptr ¶
type Uintptr struct {
// contains filtered or unexported fields
}
Uintptr is an optional uintptr
func (*Uintptr) OrElse ¶
OrElse returns the uintptr value or a default value if the value is not present
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 { ... |