sort

package
v1.201.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataType

type DataType int

DataType defines the type of data for type-aware sorting.

const (
	// String data type (lexicographic sorting).
	String DataType = iota
	// Number data type (numeric sorting).
	Number
	// Boolean data type (false < true).
	Boolean
)

type MultiSorter

type MultiSorter struct {
	// contains filtered or unexported fields
}

MultiSorter handles multi-column sorting with precedence.

func NewMultiSorter

func NewMultiSorter(sorters ...*Sorter) *MultiSorter

NewMultiSorter creates a multi-column sorter. Sorters are applied in order (primary, secondary, etc.).

func (*MultiSorter) Sort

func (ms *MultiSorter) Sort(rows [][]string, headers []string) error

Sort applies all sorters in order with stable sorting.

type Order

type Order int

Order defines sort direction.

const (
	// Ascending sort order.
	Ascending Order = iota
	// Descending sort order.
	Descending
)

type Sorter

type Sorter struct {
	Column   string
	Order    Order
	DataType DataType
}

Sorter handles single column sorting.

func NewSorter

func NewSorter(column string, order Order) *Sorter

NewSorter creates a sorter for a single column. DataType is set to String by default, use WithDataType() to override.

func ParseSortSpec

func ParseSortSpec(spec string) ([]*Sorter, error)

ParseSortSpec parses CLI sort specification. Format: "column1:asc,column2:desc" or "column1:ascending,column2:descending".

func (*Sorter) Sort

func (s *Sorter) Sort(rows [][]string, headers []string) error

Sort sorts rows in-place by the column.

func (*Sorter) WithDataType

func (s *Sorter) WithDataType(dt DataType) *Sorter

WithDataType sets explicit data type for type-aware sorting.

Jump to

Keyboard shortcuts

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