iterator.gno
0.58 Kb · 24 lines
1package datasource
2
3// NewRecordIterator returns an iterator for a list of records.
4// The iterator never returns an error and it doesn't modify the slice.
5func NewRecordIterator(records []Record) Iterator {
6 return &recordIterator{records: records}
7}
8
9type recordIterator struct {
10 records []Record
11 current Record
12}
13
14func (it *recordIterator) Err() error { return nil }
15func (it *recordIterator) Record() Record { return it.current }
16
17func (it *recordIterator) Next() bool {
18 if len(it.records) == 0 {
19 return false
20 }
21
22 it.current, it.records = it.records[0], it.records[1:]
23 return true
24}