-
Notifications
You must be signed in to change notification settings - Fork 28
Add a dd function to the collection class #117
Comments
What about the more generic |
I've already submitted a PR with the functionality you're describing. I've named it If that PR get's accepted you can do this: ...
->pipe('dd');
... imho because dd'ing a collection is so handy and you'll probably do it a lot, it could deserve it's on short function. |
I'd certainly be in favour of it. Even with The only real negatives I can see are that it's a purely development focused tool that introduces a new side effect to Collections (that they can dump their data directly to output) and the functionality can be very quickly implemented with a macro. But I'm not convinced that that's a good argument not to include something that essentially requires no maintenance due to it's simplicity and provides a good quality of life improvement to working with Collection pipelines. |
The general idea sounds good, although if the If we do do this, I think it should |
@JosephSilber I think I have a slight favor for |
@sebastiandedeyne you could still do it the old way. Just saying that 99% of the time |
Would it be worth optionally supporting passing a callback in to the
|
Nah. Just use pipe.
|
Trouble with doing this is you could say the same about models and other things. If I've done a big collection this like that I would have it in a variable anyway so could just do |
Meanwhile I've created a package containing the dd macro along with a few https://github.com/spatie/laravel-collection-macros On Friday, 19 August 2016, Gary Green notifications@github.com wrote:
Freek Van der Herten |
Closing this since we have pipe I guess. |
Image you are debugging a collection chain. You want to see what the values are after the
map
function in the example below. To do that you could wrap the code starting from the collection call until right after themap
function in add
function.It's a bit of work to debug like this. You have to insert code a the beginning of the collection and an extra closing parenthesis after the
map
function. To my eyes this isn't very readable. It's also a bit of a hassle to remove thedd
statement, that closing parenthesis is easily forgotten. I'm exaggerating the problems a bit, but debugging like this becomes tiresome real quick.If we'd add a
dd
function toCollection
the workflow can be drastically improved. This is how the function would look likeNice 'n' simple.
This is how it can be used:
To see the values after a particular step in the chain you simply have to add one line of code. It's perfectly readable. After you've done your debugging there's only one line to remove. Using for example PHPStorm's
alt
+shift
+arrow-up
andalt
+shift
+arrow-down
shortcuts the->dd()
line can be easily moved to the previous or next part of the collection chain.What are your thoughts on adding this to
Collection
? Handy? Or feature creep? I've not ran any statistics but pretty sure a lot of users will be happy with this 😄If the response is positive I'll send a PR.
The text was updated successfully, but these errors were encountered: