Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Add range() to Mojo::Collection #1361

wants to merge 1 commit into from

Conversation

jhthorsen
Copy link
Member

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/slice

Motivation

I often wanted Mojo::Collection::slice() to avoid returning undef() 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

@Grinnz
Copy link
Contributor

Grinnz commented Jun 6, 2019

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.

@jhthorsen
Copy link
Member Author

We could make a similar API with ($offset, $len), but that would not allow you to do (-4, -2), I think.

@kraih
Copy link
Member

kraih commented Jun 6, 2019

I have to admit that i do find this API confusing too.

@jhthorsen
Copy link
Member Author

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.

@jhthorsen jhthorsen closed this Jun 21, 2019
@jhthorsen
Copy link
Member Author

Based on the discussions on IRC, I'm reopening the PR.

@jhthorsen jhthorsen reopened this Jul 31, 2019
@jhthorsen
Copy link
Member Author

Calling for a vote @mojolicious/core

@kraih
Copy link
Member

kraih commented Jul 31, 2019

If you're going for the JavaScript compatibility angle the name needs to be slice.

@Grinnz
Copy link
Contributor

Grinnz commented Jul 31, 2019

I am 👍 if #1360 does not succeed as it would then fill missing functionality. But compared to #1360 I am 👎 because the API is inconsistent with Perl.

@kraih
Copy link
Member

kraih commented Jul 31, 2019

While i appreciate reusing common JavaScript APIs because most people are already familiar with them, i think #1360 is the more mojo-ish solution. 👎

@kraih kraih added the vote label Jul 31, 2019
@kraih
Copy link
Member

kraih commented Aug 7, 2019

I believe the other proposal won over this.

@kraih kraih closed this Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants