Iterator Reset #19

Closed
opened 2016-06-26 01:35:06 +00:00 by wildfire810 · 3 comments
wildfire810 commented 2016-06-26 01:35:06 +00:00 (Migrated from github.com)

Dose your iterator can reset? I mean reset from 0 position. And start another 1\2\3\4...

Dose your iterator can reset? I mean reset from 0 position. And start another 1\2\3\4...
wildfire810 commented 2016-06-26 01:35:46 +00:00 (Migrated from github.com)

Or we can use a new iterator simply

Or we can use a new iterator simply
emirpasic commented 2016-06-26 12:03:46 +00:00 (Migrated from github.com)

I can add that.

I can add that.
emirpasic commented 2016-06-27 01:15:27 +00:00 (Migrated from github.com)

@wildfire810

Added Begin(), End(), First() and Last() functions to iterators. Hope this will work out for you:

Typical usage:

it := list.Iterator()
for it.Next() {
    index, value := it.Index(), it.Value()
    ...
}
if it.First() {
    firstIndex, firstValue := it.Index(), it.Value()
    ...
}
for it.Begin(); it.Next(); {
    ...
}
for it.End(); it.Prev(); {
    index, value := it.Index(), it.Value()
    ...
}
if it.Last() {
    lastIndex, lastValue := it.Index(), it.Value()
    ...
}
@wildfire810 Added Begin(), End(), First() and Last() functions to iterators. Hope this will work out for you: Typical usage: ``` go it := list.Iterator() for it.Next() { index, value := it.Index(), it.Value() ... } ``` ``` go if it.First() { firstIndex, firstValue := it.Index(), it.Value() ... } ``` ``` go for it.Begin(); it.Next(); { ... } ``` ``` go for it.End(); it.Prev(); { index, value := it.Index(), it.Value() ... } ``` ``` go if it.Last() { lastIndex, lastValue := it.Index(), it.Value() ... } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
golibs/gms-gods#19
No description provided.