extractors

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2025 License: UPL-1.0 Imports: 1 Imported by: 0

Documentation

Overview

Package extractors provides various extractor functions and types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparator added in v2.3.0

type Comparator[T any] interface {
	Compare(obj T, comparator T) (int, error)
}

Comparator allows sorting of result sets.

func ExtractorComparator added in v2.3.0

func ExtractorComparator[E any](extractor ValueExtractor[any, E], ascending bool) Comparator[E]

ExtractorComparator returns a Comparator which will compare the extracted value and sort the results based upon the value of the ascending parameter.

type SafeComparator

type SafeComparator[E any] struct {
	Type       string                  `json:"@class,omitempty"`
	Comparator *extractorComparator[E] `json:"comparator,omitempty"`
}

SafeComparator is an internal type (exported only for serialization purpose).

func NewSafeComparator

func NewSafeComparator[E any](extractor ValueExtractor[any, E], ascending bool) *SafeComparator[E]

NewSafeComparator returns a new safe Comparator. The type parameter is E = the type of value that will be extracted.

func (*SafeComparator[T]) Compare added in v2.3.0

func (sc *SafeComparator[T]) Compare(_ T, _ T) (int, error)

Compare compares two values for sorting. Only used on the server. This is an internal type (exported only for serialization purpose).

type ValueExtractor

type ValueExtractor[T, E any] interface {
	// Extract a value from the object.
	Extract(obj T) (E, error)
}

ValueExtractor extracts a value from a given object. The type parameters are T = the type of the value to extract from and E = the type of value that will be extracted.

func Chained

func Chained[T, E any](property string) ValueExtractor[T, E]

Chained creates a ChainedExtractor from dot delimited properties. The type parameters are T = the type of the value to extract from and E = the type of value that will be extracted.

func Extract

func Extract[E any](property string) (extractor ValueExtractor[any, E])

Extract creates a ValueExtractor from an entry's value. If the property contains a "." (period), then a chained extractor is created otherwise a UniversalExtractor is created. The type parameter is E = type of extracted value.

func Identity

func Identity[V any]() ValueExtractor[any, V]

Identity returns a ValueExtractor that extracts the objects identity or key.

func Multi

func Multi(properties string) ValueExtractor[any, any]

Multi returns a value extractor that extracts multiple comma separated property values. Commonly used by aggregators such as the Reducer Aggregator. For example the following will create an aggregator that will return an array of map[K][]any with the key and the name and age attributes in a slice.

reducer := aggregators.Reducer[int](extractors.Multi("name,age"))

func Universal added in v2.3.0

func Universal[E any](property string) ValueExtractor[any, E]

Universal returns a UniversalExtractor.

Jump to

Keyboard shortcuts

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