filter

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package filter narrows a list to the rows worth looking at, the shape every tool here reaches for once a list is long enough to need a live search: a predicate to combine and apply, a smart-case substring match for the base case, and a scoped-prefix query so "kind:thread pool" or "r:foo b:bar rest" parses the same way wherever the prefixes differ.

What stays local to each caller is which prefixes it recognizes and what they mean: a "kind:" that matches a row's own field, or a "p:" that looks up a pull request, is domain knowledge this package has no way to share.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Keep

func Keep[T any](in []T, p Predicate[T]) []T

Keep returns the items of in that p keeps, preserving their order.

func Match

func Match(pattern, text string) bool

Match reports whether text contains pattern, case-insensitively unless pattern itself carries an uppercase letter. That is the rule every editor's search box uses and the one nobody has to be told, so it is the default a caller reaches for before reaching past it to a fuzzy or glob matcher of its own.

func Tokens

func Tokens(query string, scopes ...string) (string, map[string][]string)

Tokens splits query into the plain text left over and the scoped words it carries, a word being scoped when it starts with one of scopes followed by ":" (matched case-insensitively, e.g. "kind:" catches "Kind:thread" too). "kind:thread pool" with scopes "kind" gives back text "pool" and scoped["kind"] = ["thread"]; an unrecognized prefix like "p:123" against scopes "kind" is left in text untouched, since only a caller knows which prefixes it means to parse.

Types

type Predicate

type Predicate[T any] func(T) bool

Predicate reports whether one item should be kept.

func All

func All[T any](preds ...Predicate[T]) Predicate[T]

All is the predicate that keeps an item only when every one of preds does, short-circuiting scans left to right. An empty preds keeps everything.

func Any

func Any[T any](preds ...Predicate[T]) Predicate[T]

Any is the predicate that keeps an item when at least one of preds does. An empty preds keeps nothing.

func Not

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

Not inverts a predicate, which is how a caller's "not X" toggle composes with All/Any instead of needing its own inverted copy of every mode.

Jump to

Keyboard shortcuts

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