retain

package
v0.1.2 Latest Latest
Warning

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

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

Documentation

Overview

Package retain implements bounded logical-item retention from util/output-retention. Push keeps the first maxItems units and counts all omitted units exactly. Finish returns retained items and omission metadata without tool-specific semantics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ItemRetainer

type ItemRetainer[T any] struct {
	// contains filtered or unexported fields
}

ItemRetainer keeps the first maxItems logical units.

func NewItemRetainer

func NewItemRetainer[T any](maxItems int) *ItemRetainer[T]

NewItemRetainer creates a head retainer; negative limits become zero.

func (*ItemRetainer[T]) Finish

func (r *ItemRetainer[T]) Finish() Result[T]

Finish returns the retention result.

func (*ItemRetainer[T]) Push

func (r *ItemRetainer[T]) Push(item T) bool

Push observes an item, retaining it if capacity remains or counting its omission. It reports whether the item was retained.

type Result

type Result[T any] struct {
	Items     []T  // Retained subset.
	Seen      int  // Total observed items.
	Omitted   int  // Items omitted due to the budget.
	Truncated bool // Whether any items were omitted.
}

Result describes retained and omitted items.

Jump to

Keyboard shortcuts

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