logic

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NONE = "<NONE>"
	ANY  = "<ANY>"
)

Variables

View Source
var (
	SymbolAND = "&&"
	SymbolOR  = "||"
	SymbolNOT = "!"
)
View Source
var (
	ErrEmptyUnion        = stdErrors.New("no union items found")
	ErrEmptyIntersection = stdErrors.New("no intersection items found")
)

Functions

func Compare

func Compare[T Item](prev, next Logic[T]) int

func Less

func Less[T Item](prev, next Logic[T]) bool

Types

type Bool

type Bool bool

func (Bool) Compare

func (b Bool) Compare(c Item) int

type BoolOperator

type BoolOperator struct{}

func (BoolOperator) AND

func (b BoolOperator) AND(first Bool, others ...Bool) (Bool, error)

func (BoolOperator) NOT

func (b BoolOperator) NOT(input Bool) (Bool, error)

func (BoolOperator) OR

func (b BoolOperator) OR(first Bool, others ...Bool) (Bool, error)

type Item

type Item interface {
	Compare(Item) int
}

type Logic

type Logic[T Item] interface {
	fmt.Stringer
	Eval(o Operator[T]) (T, error)
	// contains filtered or unexported methods
}

Logic represents a logical target which compile to (.. ∩ .. ∩ ..) ∪ (.. ∩ .. ∩ ..) ∪ (.. ∩ .. ∩ ..) ... It follows the rules below:

  1. A ∩ !A <=> 0
  2. A ∩ B <=> B ∩ A
  3. A ∪ B <=> B ∪ A
  4. (A ∩ B) ∩ C <=> A ∩ (B ∩ C)
  5. (A ∪ B) ∪ C <=> A ∪ (B ∪ C)
  6. A ∪ (B ∩ C) <=> (A ∪ B) ∩ (A ∪ C)
  7. A ∩ (B ∪ C) <=> (A ∩ B) ∪ (A ∩ C)
  8. A ∪ (A ∩ B) <=> A
  9. A ∩ (A ∪ B) <=> A
  10. !(A ∩ B) <=> !A ∪ !B
  11. !(A ∪ B) <=> !A ∩ !B
  12. A ∪ !A <=> 1

func AND

func AND[T Item](first, second Logic[T]) Logic[T]

func False

func False[T Item]() Logic[T]

func NOT

func NOT[T Item](input Logic[T]) Logic[T]

func OR

func OR[T Item](first, second Logic[T]) Logic[T]

func True

func True[T Item]() Logic[T]

func Wrap

func Wrap[T Item](v T) Logic[T]

type Operator

type Operator[T Item] interface {
	AND(first T, others ...T) (T, error)
	OR(first T, others ...T) (T, error)
	NOT(input T) (T, error)
}

type String

type String string

func (String) Compare

func (s String) Compare(item Item) int

Jump to

Keyboard shortcuts

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