predicate

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: MIT Imports: 0 Imported by: 1

README

Tests on Linux, MacOS and Windows Go Report Card GoDoc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Predefined Match values for common cases.
	True  = BoolMatch(true)
	False = BoolMatch(false)
)

Functions

This section is empty.

Types

type BoolMatch added in v0.3.0

type BoolMatch bool

BoolMatch is a simple Match implementation based on a boolean value.

func (BoolMatch) OK added in v0.3.0

func (b BoolMatch) OK() bool

type Match added in v0.3.0

type Match interface {
	OK() bool
}

Match represents the result of a predicate evaluation.

type P

type P[T any] func(T) bool

P is a predicate function that tests whether a value of type T satisfies some condition.

func (P[T]) Or

func (p P[T]) Or(ps ...P[T]) P[T]

Or returns a predicate that is a short-circuiting logical OR of this and the given predicates. Note that P[T] only supports Or. For chained AND/OR logic, use PR[T].

type PR added in v0.3.0

type PR[T any] func(T) Match

PR is a predicate function that tests whether a value of type T satisfies some condition and returns a Match result.

func (PR[T]) And added in v0.3.0

func (p PR[T]) And(ps ...PR[T]) PR[T]

And returns a predicate that is a short-circuiting logical AND of this and the given predicates.

func (PR[T]) BoolFunc added in v0.3.0

func (p PR[T]) BoolFunc() P[T]

BoolFunc returns a P[T] version of this predicate.

func (PR[T]) Filter added in v0.3.0

func (p PR[T]) Filter(s []T) []T

Filter returns a new slice holding only the elements of s that satisfy p. Filter modifies the contents of the slice s and returns the modified slice, which may have a smaller length.

func (PR[T]) FilterCopy added in v0.3.0

func (p PR[T]) FilterCopy(s []T) []T

FilterCopy returns a new slice holding only the elements of s that satisfy p.

func (PR[T]) Or added in v0.3.0

func (p PR[T]) Or(ps ...PR[T]) PR[T]

Or returns a predicate that is a short-circuiting logical OR of this and the given predicates.

Jump to

Keyboard shortcuts

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