mirror of
https://github.com/emirpasic/gods.git
synced 2026-06-24 17:44:56 +03:00
- rename Reset() to Begin() in iterators (this will allow End() which will make reverse loops more readable)
This commit is contained in:
@@ -143,9 +143,9 @@ func (iterator *Iterator) Index() int {
|
||||
return iterator.index
|
||||
}
|
||||
|
||||
// Reset sets the iterator to the initial state.
|
||||
// Begin resets the iterator to its initial state (one-before-first)
|
||||
// Call Next() to fetch the first element if any.
|
||||
func (iterator *Iterator) Reset() {
|
||||
func (iterator *Iterator) Begin() {
|
||||
iterator.index = -1
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ func (iterator *Iterator) Reset() {
|
||||
// If First() returns true, then first element's index and value can be retrieved by Index() and Value().
|
||||
// Modifies the state of the iterator.
|
||||
func (iterator *Iterator) First() bool {
|
||||
iterator.Reset()
|
||||
iterator.Begin()
|
||||
return iterator.Next()
|
||||
}
|
||||
|
||||
|
||||
@@ -176,16 +176,16 @@ func TestStackIteratorPrev(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStackIteratorReset(t *testing.T) {
|
||||
func TestStackIteratorBegin(t *testing.T) {
|
||||
stack := New()
|
||||
it := stack.Iterator()
|
||||
it.Reset()
|
||||
it.Begin()
|
||||
stack.Push("a")
|
||||
stack.Push("b")
|
||||
stack.Push("c")
|
||||
for it.Next() {
|
||||
}
|
||||
it.Reset()
|
||||
it.Begin()
|
||||
it.Next()
|
||||
if index, value := it.Index(), it.Value(); index != 0 || value != "c" {
|
||||
t.Errorf("Got %v,%v expected %v,%v", index, value, 0, "c")
|
||||
|
||||
Reference in New Issue
Block a user