maybe

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2020 License: BSD-3-Clause Imports: 1 Imported by: 12

README

maybe

Provides optional values in go.

Representing optional values as pointers can create many small chunks on the heap. This package represents optional values without heap allocations.

This API is stable. Newly added API that is not yet stable will be clearly marked as draft API.

Using

import "github.com/keep94/maybe"

Documentation

Overview

Package maybe provides optional values as an alternative to using pointers which can lead to many small chunks on the heap. Programs using maybe instances should typically store and pass them as values, not pointers. Maybe instances fully support assignment (=) and equality (==) operators.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool struct {
	// The bool value
	Value bool
	// True if this instance represents a bool,
	// false if it represents nothing.
	Valid bool
}

Bool represents a bool value or nothing. The zero value is nothing.

func NewBool

func NewBool(x bool) Bool

NewBool returns an instance representing the value x.

func (*Bool) Clear

func (m *Bool) Clear()

Clear makes this instance represent nothing.

func (*Bool) Set

func (m *Bool) Set(x bool)

Set makes this instance represent the value x.

func (Bool) String

func (m Bool) String() string

type Float32

type Float32 struct {
	// The float32 value
	Value float32
	// True if this instance represents a float32,
	// false if it represents nothing.
	Valid bool
}

Float32 represents a float32 value or nothing. The zero value is nothing.

func NewFloat32

func NewFloat32(x float32) Float32

NewFloat32 returns an instance representing the value x.

func (*Float32) Clear

func (m *Float32) Clear()

Clear makes this instance represent nothing.

func (*Float32) Set

func (m *Float32) Set(x float32)

Set makes this instance represent the value x.

func (Float32) String

func (m Float32) String() string

type Float64

type Float64 struct {
	// The float64 value
	Value float64
	// True if this instance represents a float64,
	// false if it represents nothing.
	Valid bool
}

Float64 represents a float64 value or nothing. The zero value is nothing.

func NewFloat64

func NewFloat64(x float64) Float64

NewFloat64 returns an instance representing the value x.

func (*Float64) Clear

func (m *Float64) Clear()

Clear makes this instance represent nothing.

func (*Float64) Set

func (m *Float64) Set(x float64)

Set makes this instance represent the value x.

func (Float64) String

func (m Float64) String() string

type Int

type Int struct {
	// The int value
	Value int
	// True if this instance represents an int, false if it represents nothing.
	Valid bool
}

Int represents an int value or nothing. The zero value is nothing.

func NewInt

func NewInt(x int) Int

NewInt returns an instance representing the value x.

func (*Int) Clear

func (m *Int) Clear()

Clear makes this instance represent nothing.

func (*Int) Set

func (m *Int) Set(x int)

Set makes this instance represent the value x.

func (Int) String

func (m Int) String() string

type Int16

type Int16 struct {
	// The int16 value
	Value int16
	// True if this instance represents an int16, false if it represents nothing.
	Valid bool
}

Int16 represents an int16 value or nothing. The zero value is nothing.

func NewInt16

func NewInt16(x int16) Int16

NewInt16 returns an instance representing the value x.

func (*Int16) Clear

func (m *Int16) Clear()

Clear makes this instance represent nothing.

func (*Int16) Set

func (m *Int16) Set(x int16)

Set makes this instance represent the value x.

func (Int16) String

func (m Int16) String() string

type Int32

type Int32 struct {
	// The int32 value
	Value int32
	// True if this instance represents an int32, false if it represents nothing.
	Valid bool
}

Int32 represents an int32 value or nothing. The zero value is nothing.

func NewInt32

func NewInt32(x int32) Int32

NewInt32 returns an instance representing the value x.

func (*Int32) Clear

func (m *Int32) Clear()

Clear makes this instance represent nothing.

func (*Int32) Set

func (m *Int32) Set(x int32)

Set makes this instance represent the value x.

func (Int32) String

func (m Int32) String() string

type Int64

type Int64 struct {
	// The int64 value
	Value int64
	// True if this instance represents an int64, false if it represents nothing.
	Valid bool
}

Int64 represents an int64 value or nothing. The zero value is nothing.

func NewInt64

func NewInt64(x int64) Int64

NewInt64 returns an instance representing the value x.

func (*Int64) Clear

func (m *Int64) Clear()

Clear makes this instance represent nothing.

func (*Int64) Set

func (m *Int64) Set(x int64)

Set makes this instance represent the value x.

func (Int64) String

func (m Int64) String() string

type Int8

type Int8 struct {
	// The int8 value
	Value int8
	// True if this instance represents an int8, false if it represents nothing.
	Valid bool
}

Int8 represents an int8 value or nothing. The zero value is nothing.

func NewInt8

func NewInt8(x int8) Int8

NewInt8 returns an instance representing the value x.

func (*Int8) Clear

func (m *Int8) Clear()

Clear makes this instance represent nothing.

func (*Int8) Set

func (m *Int8) Set(x int8)

Set makes this instance represent the value x.

func (Int8) String

func (m Int8) String() string

type String

type String struct {
	// The string value
	Value string
	// True if this instance represents a string,
	// false if it represents nothing.
	Valid bool
}

String represents a string value or nothing. The zero value is nothing.

func NewString

func NewString(x string) String

NewString returns an instance representing the value x.

func (*String) Clear

func (m *String) Clear()

Clear makes this instance represent nothing.

func (*String) Set

func (m *String) Set(x string)

Set makes this instance represent the value x.

func (String) String

func (m String) String() string

type Uint

type Uint struct {
	// The uint value
	Value uint
	// True if this instance represents an uint, false if it represents nothing.
	Valid bool
}

Uint represents an uint value or nothing. The zero value is nothing.

func NewUint

func NewUint(x uint) Uint

NewUint returns an instance representing the value x.

func (*Uint) Clear

func (m *Uint) Clear()

Clear makes this instance represent nothing.

func (*Uint) Set

func (m *Uint) Set(x uint)

Set makes this instance represent the value x.

func (Uint) String

func (m Uint) String() string

type Uint16

type Uint16 struct {
	// The uint16 value
	Value uint16
	// True if this instance represents an uint16, false if it represents nothing.
	Valid bool
}

Uint16 represents an uint16 value or nothing. The zero value is nothing.

func NewUint16

func NewUint16(x uint16) Uint16

NewUint16 returns an instance representing the value x.

func (*Uint16) Clear

func (m *Uint16) Clear()

Clear makes this instance represent nothing.

func (*Uint16) Set

func (m *Uint16) Set(x uint16)

Set makes this instance represent the value x.

func (Uint16) String

func (m Uint16) String() string

type Uint32

type Uint32 struct {
	// The uint32 value
	Value uint32
	// True if this instance represents an uint32, false if it represents nothing.
	Valid bool
}

Uint32 represents an uint32 value or nothing. The zero value is nothing.

func NewUint32

func NewUint32(x uint32) Uint32

NewUint32 returns an instance representing the value x.

func (*Uint32) Clear

func (m *Uint32) Clear()

Clear makes this instance represent nothing.

func (*Uint32) Set

func (m *Uint32) Set(x uint32)

Set makes this instance represent the value x.

func (Uint32) String

func (m Uint32) String() string

type Uint64

type Uint64 struct {
	// The uint64 value
	Value uint64
	// True if this instance represents an uint64, false if it represents nothing.
	Valid bool
}

Uint64 represents an uint64 value or nothing. The zero value is nothing.

func NewUint64

func NewUint64(x uint64) Uint64

NewUint64 returns an instance representing the value x.

func (*Uint64) Clear

func (m *Uint64) Clear()

Clear makes this instance represent nothing.

func (*Uint64) Set

func (m *Uint64) Set(x uint64)

Set makes this instance represent the value x.

func (Uint64) String

func (m Uint64) String() string

type Uint8

type Uint8 struct {
	// The uint8 value
	Value uint8
	// True if this instance represents an uint8, false if it represents nothing.
	Valid bool
}

Uint8 represents an uint8 value or nothing. The zero value is nothing.

func NewUint8

func NewUint8(x uint8) Uint8

NewUint8 returns an instance representing the value x.

func (*Uint8) Clear

func (m *Uint8) Clear()

Clear makes this instance represent nothing.

func (*Uint8) Set

func (m *Uint8) Set(x uint8)

Set makes this instance represent the value x.

func (Uint8) String

func (m Uint8) String() string

Jump to

Keyboard shortcuts

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