-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathindex_iterator.go
More file actions
29 lines (22 loc) · 1.2 KB
/
index_iterator.go
File metadata and controls
29 lines (22 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package storage
import "iter"
// IndexFilter is a function that filters data entries to include in query responses.
// It takes a single entry and returns true if the entry should be included in the response.
type IndexFilter[T any] func(T) bool
// IndexIterator is an iterator over index entries.
// This is intended to be used with the `indexes` package to allow clients to collect filtered results.
type IndexIterator[T any, C any] iter.Seq2[IteratorEntry[T, C], error]
// ReconstructFunc is a function that reconstructs an output value T based on the key and value from storage.
type ReconstructFunc[T any, C any] func(C, []byte) (*T, error)
// DecodeKeyFunc is a function that decodes a storage key into a cursor C.
type DecodeKeyFunc[C any] func([]byte) (C, error)
// IteratorEntry is a single entry returned by an index iterator.
// It provides access to the cursor and value for the entry.
type IteratorEntry[T any, C any] interface {
// Cursor returns the cursor for the entry, which includes all data included in the storage key.
Cursor() C
// Value returns the fully reconstructed value for the entry.
//
// Any error indicates the value cannot be reconstructed from the storage value.
Value() (T, error)
}