package predicate

import "github.com/gohugoio/hugo/common/predicate"

Index

Variables

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

Types

type BoolMatch

type BoolMatch bool

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

func (BoolMatch) OK

func (b BoolMatch) OK() bool

type IndexMatcher

type IndexMatcher interface {
	IndexMatch(match P[string]) (iter.Seq[int], error)
}

type Match

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 NewStringPredicateFromGlobs

func NewStringPredicateFromGlobs(patterns []string, getGlob func(pattern string) (glob.Glob, error)) (P[string], error)

NewStringPredicateFromGlobs creates a string predicate from the given glob patterns. A glob pattern starting with "!" is a negation pattern which will be ANDed with the rest.

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

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

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

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

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

func (PR[T]) Filter

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

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

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.

Source Files

predicate.go

Version
v0.153.4 (latest)
Published
Dec 28, 2025
Platform
linux/amd64
Imports
4 packages
Last checked
4 months ago

Tools for package owners.