extractors

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 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 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.

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"))

Jump to

Keyboard shortcuts

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