Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[10.x] Add Arr::from() #49202

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

Closed
wants to merge 6 commits into from
Closed

Conversation

daniser
Copy link
Contributor

@daniser daniser commented Nov 30, 2023

This PR moves protected EnumeratesValues::getArrayableItems method into public static method Arr::from.

Many times I came across this hidden jewel when searching ways to convert something into array. Currently, the way to go is collect($something)->all(), but:

  • it's cumbersome and doesn't clearly reflect developer's intentions;
  • it creates collection just to destroy it microsecond later;
  • it doesn't passthrough arrays hence forcing unnecessary copying (here I try to work around this).

WDYT?

Copy link
Contributor

@stevebauman stevebauman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I personally like this extraction 👍

@taylorotwell
Copy link
Member

Please don't remove any existing tests.

@taylorotwell taylorotwell marked this pull request as draft December 1, 2023 18:51
@daniser daniser marked this pull request as ready for review December 1, 2023 19:11
@taylorotwell
Copy link
Member

Personally I'm hesitant on this. Mainly because of the WeakMap case. That feels very unique limitation related to collections but is now in this general helper method.

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.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.