tribool

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 2 Imported by: 2

README

Package tribool

The package allows to assign a 3-way state to a variable. The varible is JSON-serializable.

Documentation

Overview

package tribool implements a simple nullable three-valued construct. It can be safely serialized/deserialized by JSON libraries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tribool

type Tribool struct {
	Value int
	Valid bool
}

Tribool is a nullable three-value construct.

func New

func New(ints ...int) Tribool

New creates a Tribool out of an integer. Positive integer creates 'yes' value, 0 creates 'maybe' values, negative integer generates 'no value. If no number is given, the result represents null, if more than one number is given, other numbers are ignored.

func (Tribool) Bool

func (t Tribool) Bool() bool

Degrades data to a boolean

func (Tribool) Int

func (t Tribool) Int() int

Returns integer representation of Tribool. For "yes" it returns 1, for "no" and "null" it returns -1, and for "maybe it returns 0.

func (Tribool) MarshalJSON

func (t Tribool) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this Int is null.

func (Tribool) String

func (t Tribool) String() string

Implements fmt.String interface

func (*Tribool) UnmarshalJSON

func (t *Tribool) UnmarshalJSON(bs []byte) error

UnmarshalJSON implements json.Unmarshaller.

Jump to

Keyboard shortcuts

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