optional

package module
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2020 License: MIT Imports: 2 Imported by: 0

README

Optional

Build Status Release Software License Go Doc Go Report Card

Optional is a library that provides option types for the primitive Go types.

It can also be used as a tool to generate option type wrappers around your own types.

Motivation

In Go, variables declared without an explicit initial value are given their zero value. Most of the time this is what you want, but sometimes you want to be able to tell if a variable was set or if it's just a zero value. That's where option types come in handy.

This repository is a fork of github.com/markphelps/optional, which also provides option types for Go primitives and custom types. The driving motivation for this fork is performance. Where the original project uses pointer indirection to implement option types, this project inlines values directly into their option wrapper. This inlining avoids memory allocations, reduces garbage collection pressure, and improves cache locality.

Inspiration

Library

The library provides option types each primitive Go type:

Usage
package main

import (
	"fmt"

	"github.com/nvanbenschoten/optional"
)

func main() {
	s := optional.MakeString("foo")

	if s.Present() {
		fmt.Println(s.Get())
	} else {
		fmt.Println("missing")
	}

	if val, ok := s.GetOrBool(); ok {
		fmt.Println(val)
	} else {
		fmt.Println("missing")
	}

	if val, err := s.GetOrErr(); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(val)
	}

	t := optional.String{}
	fmt.Println(t.GetOr("bar"))
}

See example_test.go and the documentation for more usage.

Memory Layout

Each option type is composed of its value type and a bool inlined into a single struct. For example, the option type for an int32 is represented as struct{int32, bool}. The precise memory layout that this structure translates to is subject to Go's type alignment and padding rules, which make little in the way of guarantees around struct field alignment.

In practice, however, the memory layout for this struct looks like:

+---+---+---+---+---+---+---+---+
| i | i | i | i | b | p | p | p |
+---+---+---+---+---+---+---+---+

i = int32   byte
b = bool    byte
p = padding byte

total size = 8 bytes

The following table lists the memory footprint in bytes of each of the option types provided by the library when compiled for a 64-bit CPU architecture using Go 1.13.9:

Type Size (bytes)
Bool 2
Byte 2
Complex128 24
Complex64 12
Error 24
Float32 8
Float64 16
Int 16
Int16 4
Int32 8
Int64 16
Int8 2
Rune 8
String 24
Uint 16
Uint16 4
Uint32 8
Uint64 16
Uint8 2
Uintptr 16

These sizes will differ depending on target CPU architecture and may change in future compiler versions. Changes here will break the tests in size_test.go.

No effort has been made to specialize the implementation of specific option types in order to optimize for memory size. Future work may explore such optimizations in a manner akin to Rust's "niche-filling strategy".

Tool

The tool can generate option type wrappers around your own types.

Install

go get -u github.com/nvanbenschoten/optional/cmd/optional

Usage

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 {
  ...
}

The default type is OptionalT or optionalT (depending on if the type is exported) and output file is optional_t.go. This can be overridden with the -output flag.

Test Coverage

As you can see test coverage is a bit lacking for the library. This is simply because testing generated code is not super easy. I'm currently working on improving test coverage for the generated types, but in the meantime checkout string_test.go and int_test.go for examples.

Also checkout:

Golden Files

If changing the API you may need to update the golden files for your tests to pass by running:

go test ./cmd/optional/... -update.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

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

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 MakeBool added in v0.8.0

func MakeBool(v bool) Bool

MakeBool creates an optional.Bool from a bool.

func (Bool) And added in v0.8.1

func (b Bool) And(optb Bool) Bool

And returns an empty Bool option value if not present, otherwise returns optb.

func (Bool) Get

func (b Bool) Get() bool

Get returns the bool value or panics if not present.

func (Bool) GetOr added in v0.8.1

func (b Bool) GetOr(v bool) bool

GetOr returns the bool value or a default value if not present.

func (Bool) GetOrBool added in v0.8.2

func (b Bool) GetOrBool() (bool, bool)

GetOrBool returns the bool value or false if not present.

func (Bool) GetOrErr added in v0.8.1

func (b Bool) GetOrErr() (bool, error)

GetOrErr returns the bool value or an error if not present.

func (Bool) If added in v0.2.0

func (b Bool) If(fn func(bool))

If calls the function fn with the value if the value is present.

func (Bool) Map added in v0.8.1

func (b Bool) Map(fn func(bool) bool) Bool

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

func (b Bool) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Bool) Or added in v0.8.1

func (b Bool) Or(optb Bool) Bool

Or returns the Bool option value if present, otherwise returns optb.

func (Bool) Present

func (b Bool) Present() bool

Present returns whether or not the value is present.

func (*Bool) Set

func (b *Bool) Set(v bool)

Set sets the bool value.

func (*Bool) UnmarshalJSON added in v0.4.0

func (b *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Bool) Unset added in v0.8.0

func (b *Bool) Unset()

Unset unsets the bool value.

type Byte

type Byte struct {
	// contains filtered or unexported fields
}

Byte is an optional byte.

func MakeByte added in v0.8.0

func MakeByte(v byte) Byte

MakeByte creates an optional.Byte from a byte.

func (Byte) And added in v0.8.1

func (b Byte) And(optb Byte) Byte

And returns an empty Byte option value if not present, otherwise returns optb.

func (Byte) Get

func (b Byte) Get() byte

Get returns the byte value or panics if not present.

func (Byte) GetOr added in v0.8.1

func (b Byte) GetOr(v byte) byte

GetOr returns the byte value or a default value if not present.

func (Byte) GetOrBool added in v0.8.2

func (b Byte) GetOrBool() (byte, bool)

GetOrBool returns the byte value or false if not present.

func (Byte) GetOrErr added in v0.8.1

func (b Byte) GetOrErr() (byte, error)

GetOrErr returns the byte value or an error if not present.

func (Byte) If added in v0.2.0

func (b Byte) If(fn func(byte))

If calls the function fn with the value if the value is present.

func (Byte) Map added in v0.8.1

func (b Byte) Map(fn func(byte) byte) Byte

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

func (b Byte) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Byte) Or added in v0.8.1

func (b Byte) Or(optb Byte) Byte

Or returns the Byte option value if present, otherwise returns optb.

func (Byte) Present

func (b Byte) Present() bool

Present returns whether or not the value is present.

func (*Byte) Set

func (b *Byte) Set(v byte)

Set sets the byte value.

func (*Byte) UnmarshalJSON added in v0.4.0

func (b *Byte) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Byte) Unset added in v0.8.0

func (b *Byte) Unset()

Unset unsets the byte value.

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) Set

func (c *Complex128) Set(v complex128)

Set sets the complex128 value.

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

func MakeComplex64(v complex64) Complex64

MakeComplex64 creates an optional.Complex64 from a complex64.

func (Complex64) And added in v0.8.1

func (c Complex64) And(optb Complex64) Complex64

And returns an empty Complex64 option value if not present, otherwise returns optb.

func (Complex64) Get

func (c Complex64) Get() complex64

Get returns the complex64 value or panics if not present.

func (Complex64) GetOr added in v0.8.1

func (c Complex64) GetOr(v complex64) complex64

GetOr returns the complex64 value or a default value if not present.

func (Complex64) GetOrBool added in v0.8.2

func (c Complex64) GetOrBool() (complex64, bool)

GetOrBool returns the complex64 value or false if not present.

func (Complex64) GetOrErr added in v0.8.1

func (c Complex64) GetOrErr() (complex64, error)

GetOrErr returns the complex64 value or an error if not present.

func (Complex64) If added in v0.2.0

func (c Complex64) If(fn func(complex64))

If calls the function fn with the value if the value is present.

func (Complex64) Map added in v0.8.1

func (c Complex64) Map(fn func(complex64) complex64) Complex64

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

func (c Complex64) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Complex64) Or added in v0.8.1

func (c Complex64) Or(optb Complex64) Complex64

Or returns the Complex64 option value if present, otherwise returns optb.

func (Complex64) Present

func (c Complex64) Present() bool

Present returns whether or not the value is present.

func (*Complex64) Set

func (c *Complex64) Set(v complex64)

Set sets the complex64 value.

func (*Complex64) UnmarshalJSON added in v0.4.0

func (c *Complex64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Complex64) Unset added in v0.8.0

func (c *Complex64) Unset()

Unset unsets the complex64 value.

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is an optional error.

func MakeError added in v0.8.0

func MakeError(v error) Error

MakeError creates an optional.Error from a error.

func (Error) And added in v0.8.1

func (e Error) And(optb Error) Error

And returns an empty Error option value if not present, otherwise returns optb.

func (Error) Get

func (e Error) Get() error

Get returns the error value or panics if not present.

func (Error) GetOr added in v0.8.1

func (e Error) GetOr(v error) error

GetOr returns the error value or a default value if not present.

func (Error) GetOrBool added in v0.8.2

func (e Error) GetOrBool() (error, bool)

GetOrBool returns the error value or false if not present.

func (Error) GetOrErr added in v0.8.1

func (e Error) GetOrErr() (error, error)

GetOrErr returns the error value or an error if not present.

func (Error) If added in v0.2.0

func (e Error) If(fn func(error))

If calls the function fn with the value if the value is present.

func (Error) Map added in v0.8.1

func (e Error) Map(fn func(error) error) Error

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

func (e Error) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Error) Or added in v0.8.1

func (e Error) Or(optb Error) Error

Or returns the Error option value if present, otherwise returns optb.

func (Error) Present

func (e Error) Present() bool

Present returns whether or not the value is present.

func (*Error) Set

func (e *Error) Set(v error)

Set sets the error value.

func (*Error) UnmarshalJSON added in v0.4.0

func (e *Error) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Error) Unset added in v0.8.0

func (e *Error) Unset()

Unset unsets the error value.

type Float32

type Float32 struct {
	// contains filtered or unexported fields
}

Float32 is an optional float32.

func MakeFloat32 added in v0.8.0

func MakeFloat32(v float32) Float32

MakeFloat32 creates an optional.Float32 from a float32.

func (Float32) And added in v0.8.1

func (f Float32) And(optb Float32) Float32

And returns an empty Float32 option value if not present, otherwise returns optb.

func (Float32) Get

func (f Float32) Get() float32

Get returns the float32 value or panics if not present.

func (Float32) GetOr added in v0.8.1

func (f Float32) GetOr(v float32) float32

GetOr returns the float32 value or a default value if not present.

func (Float32) GetOrBool added in v0.8.2

func (f Float32) GetOrBool() (float32, bool)

GetOrBool returns the float32 value or false if not present.

func (Float32) GetOrErr added in v0.8.1

func (f Float32) GetOrErr() (float32, error)

GetOrErr returns the float32 value or an error if not present.

func (Float32) If added in v0.2.0

func (f Float32) If(fn func(float32))

If calls the function fn with the value if the value is present.

func (Float32) Map added in v0.8.1

func (f Float32) Map(fn func(float32) float32) Float32

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

func (f Float32) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Float32) Or added in v0.8.1

func (f Float32) Or(optb Float32) Float32

Or returns the Float32 option value if present, otherwise returns optb.

func (Float32) Present

func (f Float32) Present() bool

Present returns whether or not the value is present.

func (*Float32) Set

func (f *Float32) Set(v float32)

Set sets the float32 value.

func (*Float32) UnmarshalJSON added in v0.4.0

func (f *Float32) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Float32) Unset added in v0.8.0

func (f *Float32) Unset()

Unset unsets the float32 value.

type Float64

type Float64 struct {
	// contains filtered or unexported fields
}

Float64 is an optional float64.

func MakeFloat64 added in v0.8.0

func MakeFloat64(v float64) Float64

MakeFloat64 creates an optional.Float64 from a float64.

func (Float64) And added in v0.8.1

func (f Float64) And(optb Float64) Float64

And returns an empty Float64 option value if not present, otherwise returns optb.

func (Float64) Get

func (f Float64) Get() float64

Get returns the float64 value or panics if not present.

func (Float64) GetOr added in v0.8.1

func (f Float64) GetOr(v float64) float64

GetOr returns the float64 value or a default value if not present.

func (Float64) GetOrBool added in v0.8.2

func (f Float64) GetOrBool() (float64, bool)

GetOrBool returns the float64 value or false if not present.

func (Float64) GetOrErr added in v0.8.1

func (f Float64) GetOrErr() (float64, error)

GetOrErr returns the float64 value or an error if not present.

func (Float64) If added in v0.2.0

func (f Float64) If(fn func(float64))

If calls the function fn with the value if the value is present.

func (Float64) Map added in v0.8.1

func (f Float64) Map(fn func(float64) float64) Float64

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

func (f Float64) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Float64) Or added in v0.8.1

func (f Float64) Or(optb Float64) Float64

Or returns the Float64 option value if present, otherwise returns optb.

func (Float64) Present

func (f Float64) Present() bool

Present returns whether or not the value is present.

func (*Float64) Set

func (f *Float64) Set(v float64)

Set sets the float64 value.

func (*Float64) UnmarshalJSON added in v0.4.0

func (f *Float64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Float64) Unset added in v0.8.0

func (f *Float64) Unset()

Unset unsets the float64 value.

type Int

type Int struct {
	// contains filtered or unexported fields
}

Int is an optional int.

func MakeInt added in v0.8.0

func MakeInt(v int) Int

MakeInt creates an optional.Int from a int.

func (Int) And added in v0.8.1

func (i Int) And(optb Int) Int

And returns an empty Int option value if not present, otherwise returns optb.

func (Int) Get

func (i Int) Get() int

Get returns the int value or panics if not present.

func (Int) GetOr added in v0.8.1

func (i Int) GetOr(v int) int

GetOr returns the int value or a default value if not present.

func (Int) GetOrBool added in v0.8.2

func (i Int) GetOrBool() (int, bool)

GetOrBool returns the int value or false if not present.

func (Int) GetOrErr added in v0.8.1

func (i Int) GetOrErr() (int, error)

GetOrErr returns the int value or an error if not present.

func (Int) If added in v0.2.0

func (i Int) If(fn func(int))

If calls the function fn with the value if the value is present.

func (Int) Map added in v0.8.1

func (i Int) Map(fn func(int) int) Int

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

func (i Int) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Int) Or added in v0.8.1

func (i Int) Or(optb Int) Int

Or returns the Int option value if present, otherwise returns optb.

func (Int) Present

func (i Int) Present() bool

Present returns whether or not the value is present.

func (*Int) Set

func (i *Int) Set(v int)

Set sets the int value.

func (*Int) UnmarshalJSON added in v0.4.0

func (i *Int) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Int) Unset added in v0.8.0

func (i *Int) Unset()

Unset unsets the int value.

type Int16

type Int16 struct {
	// contains filtered or unexported fields
}

Int16 is an optional int16.

func MakeInt16 added in v0.8.0

func MakeInt16(v int16) Int16

MakeInt16 creates an optional.Int16 from a int16.

func (Int16) And added in v0.8.1

func (i Int16) And(optb Int16) Int16

And returns an empty Int16 option value if not present, otherwise returns optb.

func (Int16) Get

func (i Int16) Get() int16

Get returns the int16 value or panics if not present.

func (Int16) GetOr added in v0.8.1

func (i Int16) GetOr(v int16) int16

GetOr returns the int16 value or a default value if not present.

func (Int16) GetOrBool added in v0.8.2

func (i Int16) GetOrBool() (int16, bool)

GetOrBool returns the int16 value or false if not present.

func (Int16) GetOrErr added in v0.8.1

func (i Int16) GetOrErr() (int16, error)

GetOrErr returns the int16 value or an error if not present.

func (Int16) If added in v0.2.0

func (i Int16) If(fn func(int16))

If calls the function fn with the value if the value is present.

func (Int16) Map added in v0.8.1

func (i Int16) Map(fn func(int16) int16) Int16

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

func (i Int16) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Int16) Or added in v0.8.1

func (i Int16) Or(optb Int16) Int16

Or returns the Int16 option value if present, otherwise returns optb.

func (Int16) Present

func (i Int16) Present() bool

Present returns whether or not the value is present.

func (*Int16) Set

func (i *Int16) Set(v int16)

Set sets the int16 value.

func (*Int16) UnmarshalJSON added in v0.4.0

func (i *Int16) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Int16) Unset added in v0.8.0

func (i *Int16) Unset()

Unset unsets the int16 value.

type Int32

type Int32 struct {
	// contains filtered or unexported fields
}

Int32 is an optional int32.

func MakeInt32 added in v0.8.0

func MakeInt32(v int32) Int32

MakeInt32 creates an optional.Int32 from a int32.

func (Int32) And added in v0.8.1

func (i Int32) And(optb Int32) Int32

And returns an empty Int32 option value if not present, otherwise returns optb.

func (Int32) Get

func (i Int32) Get() int32

Get returns the int32 value or panics if not present.

func (Int32) GetOr added in v0.8.1

func (i Int32) GetOr(v int32) int32

GetOr returns the int32 value or a default value if not present.

func (Int32) GetOrBool added in v0.8.2

func (i Int32) GetOrBool() (int32, bool)

GetOrBool returns the int32 value or false if not present.

func (Int32) GetOrErr added in v0.8.1

func (i Int32) GetOrErr() (int32, error)

GetOrErr returns the int32 value or an error if not present.

func (Int32) If added in v0.2.0

func (i Int32) If(fn func(int32))

If calls the function fn with the value if the value is present.

func (Int32) Map added in v0.8.1

func (i Int32) Map(fn func(int32) int32) Int32

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

func (i Int32) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Int32) Or added in v0.8.1

func (i Int32) Or(optb Int32) Int32

Or returns the Int32 option value if present, otherwise returns optb.

func (Int32) Present

func (i Int32) Present() bool

Present returns whether or not the value is present.

func (*Int32) Set

func (i *Int32) Set(v int32)

Set sets the int32 value.

func (*Int32) UnmarshalJSON added in v0.4.0

func (i *Int32) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Int32) Unset added in v0.8.0

func (i *Int32) Unset()

Unset unsets the int32 value.

type Int64

type Int64 struct {
	// contains filtered or unexported fields
}

Int64 is an optional int64.

func MakeInt64 added in v0.8.0

func MakeInt64(v int64) Int64

MakeInt64 creates an optional.Int64 from a int64.

func (Int64) And added in v0.8.1

func (i Int64) And(optb Int64) Int64

And returns an empty Int64 option value if not present, otherwise returns optb.

func (Int64) Get

func (i Int64) Get() int64

Get returns the int64 value or panics if not present.

func (Int64) GetOr added in v0.8.1

func (i Int64) GetOr(v int64) int64

GetOr returns the int64 value or a default value if not present.

func (Int64) GetOrBool added in v0.8.2

func (i Int64) GetOrBool() (int64, bool)

GetOrBool returns the int64 value or false if not present.

func (Int64) GetOrErr added in v0.8.1

func (i Int64) GetOrErr() (int64, error)

GetOrErr returns the int64 value or an error if not present.

func (Int64) If added in v0.2.0

func (i Int64) If(fn func(int64))

If calls the function fn with the value if the value is present.

func (Int64) Map added in v0.8.1

func (i Int64) Map(fn func(int64) int64) Int64

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

func (i Int64) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Int64) Or added in v0.8.1

func (i Int64) Or(optb Int64) Int64

Or returns the Int64 option value if present, otherwise returns optb.

func (Int64) Present

func (i Int64) Present() bool

Present returns whether or not the value is present.

func (*Int64) Set

func (i *Int64) Set(v int64)

Set sets the int64 value.

func (*Int64) UnmarshalJSON added in v0.4.0

func (i *Int64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Int64) Unset added in v0.8.0

func (i *Int64) Unset()

Unset unsets the int64 value.

type Int8

type Int8 struct {
	// contains filtered or unexported fields
}

Int8 is an optional int8.

func MakeInt8 added in v0.8.0

func MakeInt8(v int8) Int8

MakeInt8 creates an optional.Int8 from a int8.

func (Int8) And added in v0.8.1

func (i Int8) And(optb Int8) Int8

And returns an empty Int8 option value if not present, otherwise returns optb.

func (Int8) Get

func (i Int8) Get() int8

Get returns the int8 value or panics if not present.

func (Int8) GetOr added in v0.8.1

func (i Int8) GetOr(v int8) int8

GetOr returns the int8 value or a default value if not present.

func (Int8) GetOrBool added in v0.8.2

func (i Int8) GetOrBool() (int8, bool)

GetOrBool returns the int8 value or false if not present.

func (Int8) GetOrErr added in v0.8.1

func (i Int8) GetOrErr() (int8, error)

GetOrErr returns the int8 value or an error if not present.

func (Int8) If added in v0.2.0

func (i Int8) If(fn func(int8))

If calls the function fn with the value if the value is present.

func (Int8) Map added in v0.8.1

func (i Int8) Map(fn func(int8) int8) Int8

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

func (i Int8) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Int8) Or added in v0.8.1

func (i Int8) Or(optb Int8) Int8

Or returns the Int8 option value if present, otherwise returns optb.

func (Int8) Present

func (i Int8) Present() bool

Present returns whether or not the value is present.

func (*Int8) Set

func (i *Int8) Set(v int8)

Set sets the int8 value.

func (*Int8) UnmarshalJSON added in v0.4.0

func (i *Int8) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Int8) Unset added in v0.8.0

func (i *Int8) Unset()

Unset unsets the int8 value.

type Rune

type Rune struct {
	// contains filtered or unexported fields
}

Rune is an optional rune.

func MakeRune added in v0.8.0

func MakeRune(v rune) Rune

MakeRune creates an optional.Rune from a rune.

func (Rune) And added in v0.8.1

func (r Rune) And(optb Rune) Rune

And returns an empty Rune option value if not present, otherwise returns optb.

func (Rune) Get

func (r Rune) Get() rune

Get returns the rune value or panics if not present.

func (Rune) GetOr added in v0.8.1

func (r Rune) GetOr(v rune) rune

GetOr returns the rune value or a default value if not present.

func (Rune) GetOrBool added in v0.8.2

func (r Rune) GetOrBool() (rune, bool)

GetOrBool returns the rune value or false if not present.

func (Rune) GetOrErr added in v0.8.1

func (r Rune) GetOrErr() (rune, error)

GetOrErr returns the rune value or an error if not present.

func (Rune) If added in v0.2.0

func (r Rune) If(fn func(rune))

If calls the function fn with the value if the value is present.

func (Rune) Map added in v0.8.1

func (r Rune) Map(fn func(rune) rune) Rune

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

func (r Rune) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Rune) Or added in v0.8.1

func (r Rune) Or(optb Rune) Rune

Or returns the Rune option value if present, otherwise returns optb.

func (Rune) Present

func (r Rune) Present() bool

Present returns whether or not the value is present.

func (*Rune) Set

func (r *Rune) Set(v rune)

Set sets the rune value.

func (*Rune) UnmarshalJSON added in v0.4.0

func (r *Rune) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Rune) Unset added in v0.8.0

func (r *Rune) Unset()

Unset unsets the rune value.

type String

type String struct {
	// contains filtered or unexported fields
}

String is an optional string.

func MakeString added in v0.8.0

func MakeString(v string) String

MakeString creates an optional.String from a string.

func (String) And added in v0.8.1

func (s String) And(optb String) String

And returns an empty String option value if not present, otherwise returns optb.

func (String) Get

func (s String) Get() string

Get returns the string value or panics if not present.

func (String) GetOr added in v0.8.1

func (s String) GetOr(v string) string

GetOr returns the string value or a default value if not present.

func (String) GetOrBool added in v0.8.2

func (s String) GetOrBool() (string, bool)

GetOrBool returns the string value or false if not present.

func (String) GetOrErr added in v0.8.1

func (s String) GetOrErr() (string, error)

GetOrErr returns the string value or an error if not present.

func (String) If added in v0.2.0

func (s String) If(fn func(string))

If calls the function fn with the value if the value is present.

func (String) Map added in v0.8.1

func (s String) Map(fn func(string) string) String

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

func (s String) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (String) Or added in v0.8.1

func (s String) Or(optb String) String

Or returns the String option value if present, otherwise returns optb.

func (String) Present

func (s String) Present() bool

Present returns whether or not the value is present.

func (*String) Set

func (s *String) Set(v string)

Set sets the string value.

func (*String) UnmarshalJSON added in v0.4.0

func (s *String) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*String) Unset added in v0.8.0

func (s *String) Unset()

Unset unsets the string value.

type Uint

type Uint struct {
	// contains filtered or unexported fields
}

Uint is an optional uint.

func MakeUint added in v0.8.0

func MakeUint(v uint) Uint

MakeUint creates an optional.Uint from a uint.

func (Uint) And added in v0.8.1

func (u Uint) And(optb Uint) Uint

And returns an empty Uint option value if not present, otherwise returns optb.

func (Uint) Get

func (u Uint) Get() uint

Get returns the uint value or panics if not present.

func (Uint) GetOr added in v0.8.1

func (u Uint) GetOr(v uint) uint

GetOr returns the uint value or a default value if not present.

func (Uint) GetOrBool added in v0.8.2

func (u Uint) GetOrBool() (uint, bool)

GetOrBool returns the uint value or false if not present.

func (Uint) GetOrErr added in v0.8.1

func (u Uint) GetOrErr() (uint, error)

GetOrErr returns the uint value or an error if not present.

func (Uint) If added in v0.2.0

func (u Uint) If(fn func(uint))

If calls the function fn with the value if the value is present.

func (Uint) Map added in v0.8.1

func (u Uint) Map(fn func(uint) uint) Uint

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

func (u Uint) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Uint) Or added in v0.8.1

func (u Uint) Or(optb Uint) Uint

Or returns the Uint option value if present, otherwise returns optb.

func (Uint) Present

func (u Uint) Present() bool

Present returns whether or not the value is present.

func (*Uint) Set

func (u *Uint) Set(v uint)

Set sets the uint value.

func (*Uint) UnmarshalJSON added in v0.4.0

func (u *Uint) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Uint) Unset added in v0.8.0

func (u *Uint) Unset()

Unset unsets the uint value.

type Uint16

type Uint16 struct {
	// contains filtered or unexported fields
}

Uint16 is an optional uint16.

func MakeUint16 added in v0.8.0

func MakeUint16(v uint16) Uint16

MakeUint16 creates an optional.Uint16 from a uint16.

func (Uint16) And added in v0.8.1

func (u Uint16) And(optb Uint16) Uint16

And returns an empty Uint16 option value if not present, otherwise returns optb.

func (Uint16) Get

func (u Uint16) Get() uint16

Get returns the uint16 value or panics if not present.

func (Uint16) GetOr added in v0.8.1

func (u Uint16) GetOr(v uint16) uint16

GetOr returns the uint16 value or a default value if not present.

func (Uint16) GetOrBool added in v0.8.2

func (u Uint16) GetOrBool() (uint16, bool)

GetOrBool returns the uint16 value or false if not present.

func (Uint16) GetOrErr added in v0.8.1

func (u Uint16) GetOrErr() (uint16, error)

GetOrErr returns the uint16 value or an error if not present.

func (Uint16) If added in v0.2.0

func (u Uint16) If(fn func(uint16))

If calls the function fn with the value if the value is present.

func (Uint16) Map added in v0.8.1

func (u Uint16) Map(fn func(uint16) uint16) Uint16

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

func (u Uint16) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Uint16) Or added in v0.8.1

func (u Uint16) Or(optb Uint16) Uint16

Or returns the Uint16 option value if present, otherwise returns optb.

func (Uint16) Present

func (u Uint16) Present() bool

Present returns whether or not the value is present.

func (*Uint16) Set

func (u *Uint16) Set(v uint16)

Set sets the uint16 value.

func (*Uint16) UnmarshalJSON added in v0.4.0

func (u *Uint16) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Uint16) Unset added in v0.8.0

func (u *Uint16) Unset()

Unset unsets the uint16 value.

type Uint32

type Uint32 struct {
	// contains filtered or unexported fields
}

Uint32 is an optional uint32.

func MakeUint32 added in v0.8.0

func MakeUint32(v uint32) Uint32

MakeUint32 creates an optional.Uint32 from a uint32.

func (Uint32) And added in v0.8.1

func (u Uint32) And(optb Uint32) Uint32

And returns an empty Uint32 option value if not present, otherwise returns optb.

func (Uint32) Get

func (u Uint32) Get() uint32

Get returns the uint32 value or panics if not present.

func (Uint32) GetOr added in v0.8.1

func (u Uint32) GetOr(v uint32) uint32

GetOr returns the uint32 value or a default value if not present.

func (Uint32) GetOrBool added in v0.8.2

func (u Uint32) GetOrBool() (uint32, bool)

GetOrBool returns the uint32 value or false if not present.

func (Uint32) GetOrErr added in v0.8.1

func (u Uint32) GetOrErr() (uint32, error)

GetOrErr returns the uint32 value or an error if not present.

func (Uint32) If added in v0.2.0

func (u Uint32) If(fn func(uint32))

If calls the function fn with the value if the value is present.

func (Uint32) Map added in v0.8.1

func (u Uint32) Map(fn func(uint32) uint32) Uint32

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

func (u Uint32) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Uint32) Or added in v0.8.1

func (u Uint32) Or(optb Uint32) Uint32

Or returns the Uint32 option value if present, otherwise returns optb.

func (Uint32) Present

func (u Uint32) Present() bool

Present returns whether or not the value is present.

func (*Uint32) Set

func (u *Uint32) Set(v uint32)

Set sets the uint32 value.

func (*Uint32) UnmarshalJSON added in v0.4.0

func (u *Uint32) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Uint32) Unset added in v0.8.0

func (u *Uint32) Unset()

Unset unsets the uint32 value.

type Uint64

type Uint64 struct {
	// contains filtered or unexported fields
}

Uint64 is an optional uint64.

func MakeUint64 added in v0.8.0

func MakeUint64(v uint64) Uint64

MakeUint64 creates an optional.Uint64 from a uint64.

func (Uint64) And added in v0.8.1

func (u Uint64) And(optb Uint64) Uint64

And returns an empty Uint64 option value if not present, otherwise returns optb.

func (Uint64) Get

func (u Uint64) Get() uint64

Get returns the uint64 value or panics if not present.

func (Uint64) GetOr added in v0.8.1

func (u Uint64) GetOr(v uint64) uint64

GetOr returns the uint64 value or a default value if not present.

func (Uint64) GetOrBool added in v0.8.2

func (u Uint64) GetOrBool() (uint64, bool)

GetOrBool returns the uint64 value or false if not present.

func (Uint64) GetOrErr added in v0.8.1

func (u Uint64) GetOrErr() (uint64, error)

GetOrErr returns the uint64 value or an error if not present.

func (Uint64) If added in v0.2.0

func (u Uint64) If(fn func(uint64))

If calls the function fn with the value if the value is present.

func (Uint64) Map added in v0.8.1

func (u Uint64) Map(fn func(uint64) uint64) Uint64

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

func (u Uint64) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Uint64) Or added in v0.8.1

func (u Uint64) Or(optb Uint64) Uint64

Or returns the Uint64 option value if present, otherwise returns optb.

func (Uint64) Present

func (u Uint64) Present() bool

Present returns whether or not the value is present.

func (*Uint64) Set

func (u *Uint64) Set(v uint64)

Set sets the uint64 value.

func (*Uint64) UnmarshalJSON added in v0.4.0

func (u *Uint64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Uint64) Unset added in v0.8.0

func (u *Uint64) Unset()

Unset unsets the uint64 value.

type Uint8

type Uint8 struct {
	// contains filtered or unexported fields
}

Uint8 is an optional uint8.

func MakeUint8 added in v0.8.0

func MakeUint8(v uint8) Uint8

MakeUint8 creates an optional.Uint8 from a uint8.

func (Uint8) And added in v0.8.1

func (u Uint8) And(optb Uint8) Uint8

And returns an empty Uint8 option value if not present, otherwise returns optb.

func (Uint8) Get

func (u Uint8) Get() uint8

Get returns the uint8 value or panics if not present.

func (Uint8) GetOr added in v0.8.1

func (u Uint8) GetOr(v uint8) uint8

GetOr returns the uint8 value or a default value if not present.

func (Uint8) GetOrBool added in v0.8.2

func (u Uint8) GetOrBool() (uint8, bool)

GetOrBool returns the uint8 value or false if not present.

func (Uint8) GetOrErr added in v0.8.1

func (u Uint8) GetOrErr() (uint8, error)

GetOrErr returns the uint8 value or an error if not present.

func (Uint8) If added in v0.2.0

func (u Uint8) If(fn func(uint8))

If calls the function fn with the value if the value is present.

func (Uint8) Map added in v0.8.1

func (u Uint8) Map(fn func(uint8) uint8) Uint8

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

func (u Uint8) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Uint8) Or added in v0.8.1

func (u Uint8) Or(optb Uint8) Uint8

Or returns the Uint8 option value if present, otherwise returns optb.

func (Uint8) Present

func (u Uint8) Present() bool

Present returns whether or not the value is present.

func (*Uint8) Set

func (u *Uint8) Set(v uint8)

Set sets the uint8 value.

func (*Uint8) UnmarshalJSON added in v0.4.0

func (u *Uint8) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Uint8) Unset added in v0.8.0

func (u *Uint8) Unset()

Unset unsets the uint8 value.

type Uintptr

type Uintptr struct {
	// contains filtered or unexported fields
}

Uintptr is an optional uintptr.

func MakeUintptr added in v0.8.0

func MakeUintptr(v uintptr) Uintptr

MakeUintptr creates an optional.Uintptr from a uintptr.

func (Uintptr) And added in v0.8.1

func (u Uintptr) And(optb Uintptr) Uintptr

And returns an empty Uintptr option value if not present, otherwise returns optb.

func (Uintptr) Get

func (u Uintptr) Get() uintptr

Get returns the uintptr value or panics if not present.

func (Uintptr) GetOr added in v0.8.1

func (u Uintptr) GetOr(v uintptr) uintptr

GetOr returns the uintptr value or a default value if not present.

func (Uintptr) GetOrBool added in v0.8.2

func (u Uintptr) GetOrBool() (uintptr, bool)

GetOrBool returns the uintptr value or false if not present.

func (Uintptr) GetOrErr added in v0.8.1

func (u Uintptr) GetOrErr() (uintptr, error)

GetOrErr returns the uintptr value or an error if not present.

func (Uintptr) If added in v0.2.0

func (u Uintptr) If(fn func(uintptr))

If calls the function fn with the value if the value is present.

func (Uintptr) Map added in v0.8.1

func (u Uintptr) Map(fn func(uintptr) uintptr) Uintptr

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

func (u Uintptr) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Uintptr) Or added in v0.8.1

func (u Uintptr) Or(optb Uintptr) Uintptr

Or returns the Uintptr option value if present, otherwise returns optb.

func (Uintptr) Present

func (u Uintptr) Present() bool

Present returns whether or not the value is present.

func (*Uintptr) Set

func (u *Uintptr) Set(v uintptr)

Set sets the uintptr value.

func (*Uintptr) UnmarshalJSON added in v0.4.0

func (u *Uintptr) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Uintptr) Unset added in v0.8.0

func (u *Uintptr) Unset()

Unset unsets the uintptr value.

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 { ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL