-
-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plenary list #109
Plenary list #109
Conversation
I think let's call it |
Do you mean the class, the module or both? |
I should probably mention that i did some work for a Array class that keeps track of the size, because Performance diff for scandir on homedir with hidden (100 runs)
|
Fair enough. Your implementation seems a bit more complete than mine 😅 |
I don't need to finish my implementation so you can do it and i just port the changes to scandir so its faster 😆 I would also put it in a Edit: e.g. i need a |
Ah ok 👍🏾 |
There we go. Some simple methods for iterating forwards and backwards. Let me know what you think 😃 |
👍 Good job. I will try to use this branch. I don't think you need to add a next function. I can emulate this myself. I am also not sure about the size storing, we could do some |
Fair enough. I chose a weak table since we don't need to keep track of the actual instance, and when all other references to it are gone, the entry in lendb gets collected as well |
I also think that storing the size inside of the list would be better. We don't need weak ref tables because it is a field inside of the list, which seems much simpler. Also, I don't know if hashing a table is a good idea, it might be slower than just hashing a primitive but I am not sure. |
Should we have a |
|
you could probably create a function that uses |
Some other methods that would be cool to have, |
I don't think you should add those higher order functions as they are just duplicates of the ones from the iterator library |
I think I should, in case the user wants to chain them. Like so local list1 = List {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
list1:reverse():filter_indexed(function(i, e)
return i % 3 == 0 or e % 3 == 0
end):map(function(e)
return tostring(e) .. ' little puppies'
end):for_each(print)
--[[ result:
0 little puppies
9 little puppies
8 little puppies
6 little puppies
5 little puppies
3 little puppies
2 little puppies
]] This way, you have the choice of chaining the functions like in kotlin or java, or using a functional approach |
That does the exact same thing as iterators already do. You can chain iterators |
Oh, I hadn't realized. I'll change it now. In another note, should we have a method |
Also the functions you added are probably much slower, they allocate a new table for each function |
Yes, you can create a |
A caveat I've run into, is that you can only use the |
I think this looks good -- let's merge and we can play around with it as people use it. Sorry for the long delay :) |
Thanks 😃 |
This PR adds an implementation of python-like lists, with a syntax similar to that of penlight's
pl.List
class. List-like tables are pretty barebones by default imo, so it would be nice to have an implementation that is a little bit more powerful and object oriented, providing basic operations and sintactic sugar. Over time, I plan on extending the implementation even further, wrapping vim's builtin list functions to work with it.Since the methods are all accessed through the
List
metatable, callingvim.tbl_islist(List{1,2,3})
yields true.Basic methods like
index
,append
andcount
are also provided. I'm unsure as if to implement methods like map, and join, since they seem to be covered byplenary.functional
.There is a caveat that you cannot use the
==
operator directly between a List and a normal table, since it's part of lua's design, so anequal()
method is provided as well as a workaround.Usage: