pickone

package
v1.36.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package pickone resolves a user-supplied identifier to exactly one record from an in-memory candidate list.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNone reports that no tier matched any candidate.
	ErrNone = errors.New("no match")
	// ErrAmbiguous reports that the deciding tier matched more than one candidate.
	ErrAmbiguous = errors.New("ambiguous")
)

Functions

func One

func One[T any](items []T, arg string, tiers ...Tier[T]) (T, []T, error)

One tries each tier in order, and the first tier matching any candidate decides: one match is returned, more than one returns those candidates with ErrAmbiguous, and a later tier is never consulted to break the tie. ErrNone means no tier matched.

Types

type Tier

type Tier[T any] func(item T, arg string) bool

Tier reports whether a candidate is identified by arg under one identifier.

func Exact

func Exact[T any](key func(T) string) Tier[T]

Exact matches when key(item) equals arg byte for byte. An empty key never matches.

func Fold

func Fold[T any](key func(T) string) Tier[T]

Fold matches when key(item) equals arg under Unicode case folding. An empty key never matches.

Jump to

Keyboard shortcuts

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