What do you think about Enumerator? #8
Labels
No labels
bug
discussion
documentation
duplicate
ignore
new feature
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
golibs/gms-gods#8
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What do you think about Enumerator? In offical library, there is "container/list", it contains Element, that can take values one by one. I think it takes less complex then every time find it.
Enumerator similar to C++ STL iterators, Ruby's Enumerator and Java's Enumeration classes that allows for internal and external iteration? I wanted to do that from the start, but never found the time for it. I think that's a great addition and allows for writing more optimized code! Let me first do some research on how other languages had implemented it, because this would require a large change and only ordered collection can support this feature.
great work
There are a few ways of implementing this.
I'd exclude the channels approach (inc. buffered channels) for performance reasons (albeit the channels have gotten faster) and (mis/over)use thereof. People seem to open a channel nowadays to add two numbers together and it feels like going after a fly with a bazooka just because bazookas are cool.
Also I am uneasy about the performance of the closurer approach .
So that leaves me with two patterns:
Despite being inclined towards Ruby's readability (dreaming of each/map/select/etc.), I will run some tests on both approaches this weekend and see which one works and looks better.
Thanks for pointing this out, it will be great addition to this project 👍
@wildfire810
I started working on enumerables and would appreciate your opinion if you would use this:
Currently the enumrable interface supports the following:
Current implementation is on
enumerablebranch and is purely Ruby inspired for readability. Only arraylist currently implemented, pending opinion if this is usable.I think it's ok. But ciuld you think about cpp iterator? If we want to use it throw the Each func on above, we must use channel to yield the loop. If we want to use list1[x] list2[x] and so on...one by one, we can not break the loop and continue it unless using channel. Or we use get func, the performance will be degenerate
Good point and I hope you won't need channels for this. So I think I'll keep the above Ruby inspired Enumerable and I'll also add the c++ stateful iterators:
Does this work for you?
For multiple lists it goes the same:
I think that's the cleanest pattern for god's containers, since there is no operator overloading.
I think it's very good!
Can add insert func with iter?
Insert func is already on master, thus I closed that issue: List's insert definition Example in test
Did you mean the above or the possibility to insert values into list during iteration (which would be hard)?
This is almost done, PR is up, but need to update with examples and documentatio. Then I will merge it, for now you can checkout #12 if that's OK with you. Thanks again for giving me inspiration to do this :)
thanks a lot for your work:) with pleasure
Is there reverse Iterator?
No, not yet, but it would be good to have, especially for some data structures where that is natural. For singly linked list that wouldn't be feasible, but for doubly linked list it would make absolute sense.
Can you open a new issue for reverse iterators please, because I am merging the PR that closes this issue. I'll tackle the reverse iterators in another issue + PR.