-
Notifications
You must be signed in to change notification settings - Fork 576
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
Add range() to Mojo::Collection #1361
Conversation
ea310db
to
16cd641
Compare
16cd641
to
d3f9760
Compare
Functionally this would be able to serve the same purpose as head and tail methods so I am in favor. But I prefer the head and tail methods as an API. The slice API this is based on is confusing to me, and not consistent with other Perl APIs. |
We could make a similar API with |
I have to admit that i do find this API confusing too. |
I also found the JavaScript API confusing in the beginning, but now I really like it. Either way, I'm closing this PR because of lack of interest. |
Based on the discussions on IRC, I'm reopening the PR. |
Calling for a vote @mojolicious/core |
If you're going for the JavaScript compatibility angle the name needs to be |
While i appreciate reusing common JavaScript APIs because most people are already familiar with them, i think #1360 is the more mojo-ish solution. 👎 |
I believe the other proposal won over this. |
Summary
Method for Mojo::Collection to create new collections with the same API as
slice()
in JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sliceMotivation
I often wanted
Mojo::Collection::slice()
to avoid returningundef()
elements when specifying a range outside of the collection's size, and also allow specifying a range with negative indexes.References
This idea (finally) came to life from the discussions/PR below and conversations on IRC, earlier today.
#1350
#1360