prop

package
v0.0.0-...-b03ede8 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package prop (Propositional Logic) provides utilities for building and evaluating logical propositions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Predicate

type Predicate[T any] func(T) bool

Predicate is a function that takes a value and decides if it meets a condition. In formal terms, it represents a boolean-valued function f: T → Bool that tests whether a value of type T satisfies a given condition.

func AllOf

func AllOf[T any](ps ...Predicate[T]) Predicate[T]

AllOf creates a condition that is satisfied when all input conditions are satisfied. When given no conditions, returns a condition that is always satisfied. Formally, it returns the n-ary logical conjunction (∧) of the provided predicates, representing f(x) = p₁(x) ∧ p₂(x) ∧ ... ∧ pₙ(x).

func And

func And[T any](p1, p2 Predicate[T]) Predicate[T]

And creates a condition that is satisfied only when both input conditions are satisfied. Formally, it returns the logical conjunction (∧) of predicates p1 and p2, representing f(x) = p1(x) ∧ p2(x).

func AnyOf

func AnyOf[T any](ps ...Predicate[T]) Predicate[T]

AnyOf creates a condition that is satisfied when any of the input conditions are satisfied. When given no conditions, returns a condition that is never satisfied. Formally, it returns the n-ary logical disjunction (∨) of the provided predicates, representing f(x) = p₁(x) ∨ p₂(x) ∨ ... ∨ pₙ(x).

func Eq

func Eq[T comparable](x T) Predicate[T]

Eq creates a condition that checks if a value matches the target value exactly. Formally, it returns a predicate that tests for equality with value x, representing f(y) = (x == y).

func False

func False[T any]() Predicate[T]

False creates a condition that is never satisfied. Formally, it returns a predicate that represents the constant function f(x) = false.

func Gt

func Gt[T cmp.Ordered](x T) Predicate[T]

Gt creates a predicate that checks if the value is greater than the given value.

func Gte

func Gte[T cmp.Ordered](x T) Predicate[T]

Gte creates a predicate that checks if the value is greater than or equal to the given value.

func Lt

func Lt[T cmp.Ordered](x T) Predicate[T]

Lt creates a predicate that checks if the value is less than the given value.

func Lte

func Lte[T cmp.Ordered](x T) Predicate[T]

Lte creates a predicate that checks if the value is less than or equal to the given value.

func Not

func Not[T any](p Predicate[T]) Predicate[T]

Not creates a condition that is satisfied when the original condition is not. Formally, it returns the logical complement (¬) of predicate p, representing f(x) = ¬p(x).

func Or

func Or[T any](p1, p2 Predicate[T]) Predicate[T]

Or creates a condition that is satisfied when at least one input condition is satisfied. Formally, it returns the logical disjunction (∨) of predicates p1 and p2, representing f(x) = p1(x) ∨ p2(x).

func True

func True[T any]() Predicate[T]

True creates a condition that is always satisfied. Formally, it returns a predicate that represents the constant function f(x) = true.

Jump to

Keyboard shortcuts

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