filter

package
v0.0.0-...-0bec3fc Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package filter implements https://google.aip.dev/160. This is used to filter a collection using a "structured syntax accessible to a non-technical audience."

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Evaluator

func Evaluator[T any](e Expr, functions Functions) (func(T) bool, []string)

Evaluator takes an Expr and an arbitrary Go type. It returns a function that takes an argument of that Go type and reports whether it matches the expression. The functions argument contains functions the filter expression may call. Evaluator also returns a list of warning messages about the expression.

Types

type Expr

type Expr interface {
	String() string // returns a multi-line string representation
	// contains filtered or unexported methods
}

Expr is the parsed AST of a filter expression.

func ParseFilter

func ParseFilter(filter string) (Expr, error)

ParseFilter parses a filter expression into an Expr. Empty input returns nil, nil. filter = [ expression ] ;

type Functions

type Functions map[string]any

Functions is a set of functions that are permitted when filtering. Each value in the map must be a function. Each function must take at least one argument, which is the type T in Evaluator[T]. The function may take other arguments, which will come from the filter expression. The function should return one or two results; the first result is the type that the function returns, and the optional second result is type error.

Jump to

Keyboard shortcuts

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