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

[8.x] Add pipeThrough collection method #40253

Merged
merged 3 commits into from
Jan 4, 2022
Merged

[8.x] Add pipeThrough collection method #40253

merged 3 commits into from
Jan 4, 2022

Conversation

stevebauman
Copy link
Contributor

Description

This PR adds the pipeThrough() method for collections, allowing developers to insert an array of pipe callbacks that can manipulate the collection, carrying the return value from the previous pipe into following pipes.

Usage

$pipes = [
    fn ($podcasts) => $podcasts->each(
        fn ($podcast) => $podcast->process()
    ),

    fn ($podcasts) => $podcasts->sum(
        fn ($podcast) => $podcast->hasProcessed()
    ),
];

$processed = Podcast::all()->pipeThrough($pipes);

Let me know if you would like anything adjusted. Thanks for your time! No hard feelings on closure ❤️

@taylorotwell taylorotwell merged commit ab29010 into laravel:8.x Jan 4, 2022
@stevebauman stevebauman deleted the add-collection-pipe-through branch January 19, 2022 16:33
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.

2 participants