File: iterator.go

package info (click to toggle)
aerc 0.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,892 kB
  • sloc: ansic: 1,181; python: 1,000; sh: 553; awk: 360; makefile: 23
file content (35 lines) | stat: -rw-r--r-- 1,268 bytes parent folder | download
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
30
31
32
33
34
35
package iterator

// Factory is the interface that wraps the NewIterator method. The
// NewIterator() creates either UID or thread iterators and ensures that both
// types of iterators implement the same iteration direction.
type Factory interface {
	NewIterator(a any) Iterator
}

// Iterator implements an interface for iterating over UID or thread data. If
// Next() returns true, the current value of the iterator can be read with
// Value(). The return value of Value() is of type `any` and needs to be cast to
// the correct type.
//
// The iterators are implemented such that the first returned value always
// represents the top message in the message list. Hence, StartIndex() would
// return the index of the top message whereas EndIndex() returns the index of
// message at the bottom of the list.
type Iterator interface {
	Next() bool
	Value() any
	StartIndex() int
	EndIndex() int
}

// NewFactory creates an iterator factory. When reverse is true, the iterators
// are reversed in the sense that the lowest UID messages are displayed at the
// top of the message list. Otherwise, the default order is with the highest
// UID message on top.
func NewFactory(reverse bool) Factory {
	if reverse {
		return &reverseFactory{}
	}
	return &defaultFactory{}
}