Can I set iterator index? #95

Closed
opened 2018-11-06 05:09:15 +00:00 by mcauto · 4 comments
mcauto commented 2018-11-06 05:09:15 +00:00 (Migrated from github.com)
var list *arraylist.List
list = {0,1,2,3,4,5}
it := list.Iterator()
it.SetIndex(3);
it.Next(); // 4
```go var list *arraylist.List list = {0,1,2,3,4,5} it := list.Iterator() it.SetIndex(3); it.Next(); // 4 ```
emirpasic commented 2018-11-06 10:56:57 +00:00 (Migrated from github.com)

Not at the moment, but somebody proposed something interesting:

All three, including yourself, are asking for the same thing more or less, i.e. the ability to get the iterator from a specific location. For key-value structures that's the key, for others perhaps the index.

Not sure if I will call it list.IteratorAt(1) / tree.iteratorAt('someKey') or seek(), but this will definitively be implemented in future! Keeping this issue open until it's implemented on all structures that can be iterated.

Not at the moment, but somebody proposed something interesting: - https://github.com/emirpasic/gods/pull/72/files#r219696954 - https://github.com/emirpasic/gods/issues/66 All three, including yourself, are asking for the same thing more or less, i.e. the ability to get the iterator from a specific location. For key-value structures that's the key, for others perhaps the index. Not sure if I will call it `list.IteratorAt(1)` / `tree.iteratorAt('someKey')` or `seek()`, but this will definitively be implemented in future! Keeping this issue open until it's implemented on all structures that can be iterated.
mcauto commented 2018-11-10 08:51:54 +00:00 (Migrated from github.com)

I think making setter method in iterator is better than IteratorAt() or seek() What do you think?

I think making setter method in iterator is better than `IteratorAt()` or `seek()` What do you think?
emirpasic commented 2018-11-12 10:44:06 +00:00 (Migrated from github.com)

@mcauto I don't have a strong opinion on either.

so SetIndex() and SetKey() would move the iterator to the given index/key, right?

@mcauto I don't have a strong opinion on either. so `SetIndex()` and `SetKey()` would move the iterator to the given index/key, right?
emirpasic commented 2022-04-11 23:43:48 +00:00 (Migrated from github.com)

#189 Implements the NextTo iterator function.

@mcauto please let me know if the below implements the requested functionality so that I can reopen this issue:

	seek := func(index int, value interface{}) bool {
		return index == 3
	}
	for found := it.NextTo(seek); found; found = it.Next() {
		index, value := it.Index(), it.Value()
	}

PS. I hope that this NextTo function can support the requested functionality rather than adding more functions (SetIndex and SetKey). The reason is to keep GoDS as minimal as possible and yet flexible. But please let me know if it is not what you asked for and I'll reevaluate again, adding SetIndex and SetKey is simple

#189 Implements the NextTo iterator function. @mcauto please let me know if the below implements the requested functionality so that I can reopen this issue: ```go seek := func(index int, value interface{}) bool { return index == 3 } for found := it.NextTo(seek); found; found = it.Next() { index, value := it.Index(), it.Value() } ``` PS. I hope that this NextTo function can support the requested functionality rather than adding more functions (SetIndex and SetKey). The reason is to keep GoDS as minimal as possible and yet flexible. But please let me know if it is not what you asked for and I'll reevaluate again, adding SetIndex and SetKey is simple
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#95
No description provided.