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

head and tail methods for Mojo::Collection #1360

Merged
merged 1 commit into from
Jul 31, 2019
Merged

Conversation

Grinnz
Copy link
Contributor

@Grinnz Grinnz commented Jun 5, 2019

Summary

Methods for Mojo::Collection to create new collections of the beginning or end of the collection.

Algorithms for the methods were adapted from List::Util::PP. We could just delegate to List::Util for XS functions but it would require List::Util 1.50.

Motivation

It can be useful to operate on the beginning or end of the collection during a chain without calculating slice indexes, and resulting in no extra undef elements when going past the original collection indexes.

References

#1350

Algorithms adapted from List::Util::PP
@s1037989
Copy link
Contributor

s1037989 commented Jun 5, 2019

👍 Love it!

@kraih
Copy link
Member

kraih commented Jun 5, 2019

Like i said on IRC, it's pretty hard to justify adding so much code for a feature with such limited scope. Are there any good use cases related to Mojo::DOM or Mojo::Pg? Think i would be more ok with it if the methods were List::Util based one-liners and we were already depending on List::Util 1.50 for other reasons (like some of its other functions being used to improve Mojo::Parameters or similar).

@jhthorsen
Copy link
Member

jhthorsen commented Jun 5, 2019

I guess range() would be sort of a competing feature? #1361

$c->range(-2) == tail
$c->range(0, 2) == head

@Grinnz
Copy link
Contributor Author

Grinnz commented Jun 5, 2019

range and head/tail would accomplish largely the same things. I'm not sure I can say which is clearer or nicer to use.

@marcusramberg
Copy link
Member

I prefer #1361.

@kraih
Copy link
Member

kraih commented Jul 1, 2019

I just did some tests, and the pair functions in List::Util are very very slow. So that option of bumping the dependency is ruled out.

@kraih
Copy link
Member

kraih commented Jul 9, 2019

Since there have been no changes in some time, and the proposal is kinda complete. I'm just calling for a vote @mojolicious/core!

@kraih
Copy link
Member

kraih commented Jul 9, 2019

The feature seems useful, but i don't think it's useful enough to require so much code. So, i'll be voting neutral.

@kraih
Copy link
Member

kraih commented Jul 9, 2019

Maybe worth mentioning that Mojo::Collection::slice is deprecated now. So there is no alternative at all in the Mojo::Collection API anymore.

@jhthorsen
Copy link
Member

Just as a reminder: #1361 was my alternative, but I closed it since there wasn’t any interest. I still think it’s a good idea to mimic JavaScript though.

@jberger
Copy link
Member

jberger commented Jul 31, 2019

I am in favor of both this and/or #1361. Sorry I'm late to the vote, vacation got in the way

@marcusramberg
Copy link
Member

I think such a feature should exist, but guess I'm neutral to head/tail

Sent with GitHawk

@kraih
Copy link
Member

kraih commented Jul 31, 2019

I've changed my vote to 👍, since there is a lot of interest in this functionality and i can't think of a more mojo-ish solution.

@Grinnz Grinnz force-pushed the collection_head_tail branch 2 times, most recently from faf5056 to 256c884 Compare July 31, 2019 18:30
@Grinnz Grinnz merged commit 03a4168 into master Jul 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants