trinary

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HasTrinary

type HasTrinary interface {
	ToTrinary() Value
}

type IsUndefined

type IsUndefined interface {
	IsUndefined() bool
}

type Value

type Value int

Value represents a trinary outcome: True, False, or Unknown.

const (
	False Value = iota - 1
	Unknown
	True
)

func From

func From(v any) Value

From coerces any Go value into a trinary Value:

  • nil or IsUndefined → Unknown
  • HasTrinary / Value → delegates directly
  • bool → True/False
  • numeric primitives (int/uint/float families) → True when != 0
  • string → textual keywords first, otherwise True when len > 0
  • pointers and interfaces → dereference once and retry
  • reflected string/slice/array/map kinds → reuse the string/len rules
  • everything else defaults to True (non-nil structs, etc.)

func FromToken

func FromToken(t tokens.Instance) Value

func Parse

func Parse(s string) Value

Parse parses a string into a trinary value. It converts:

  • 1, t, T, TRUE, true, True => True
  • 0, f, F, FALSE, false, False => False
  • -1, n, N, UNKNOWN, unknown, Unknown => Unknown

Any other value returns Unknown.

func (Value) And

func (r Value) And(other Value) Value

And implements tri-state AND using Kleene logic. | **AND** | **True** | **False** | **Unknown** | | ----------- | -------- | --------- | ----------- | | **True** | True | False | Unknown | | **False** | False | False | False | | **Unknown** | Unknown | False | Unknown |

func (Value) Equals

func (r Value) Equals(other Value) bool

func (Value) IsTrue

func (r Value) IsTrue() bool

Istrue returns true if the value is Pass

func (Value) MarshalJSON

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

func (Value) Not

func (r Value) Not() Value

Not implements logical NOT. True -> False, False -> True, Unknown -> Unknown

func (Value) Or

func (r Value) Or(other Value) Value

Or implements tri-state OR as a Kleene logic. | **OR** | **True** | **False** | **Unknown** | | ----------- | -------- | --------- | ----------- | | **True** | True | True | True | | **False** | True | False | Unknown | | **Unknown** | True | Unknown | Unknown |

func (Value) String

func (r Value) String() string

Jump to

Keyboard shortcuts

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