Skip to content

[7.x] Add skipUntil and skipWhile methods to the collections #32672

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

Merged
merged 3 commits into from
May 4, 2020

Conversation

JosephSilber
Copy link
Contributor

@JosephSilber JosephSilber commented May 4, 2020

This is the counterpart of takeWhile and takeUntil.


Here's a sample usage, using the log file example of my original LazyCollection PR (example 4).

We'll skip all logs that are from previous years:

function get_logs_from_this_year()
{
    $year = date("Y");

    return LazyCollection::make(function () {
        $handle = fopen('log.txt', 'r');

        while (($line = fgets($handle)) !== false) {
            yield $line;
        }
    })
    ->chunk(4)
    ->skipUntil(fn ($lines) => Str::startsWith($lines[0], $year))
    ->map(fn ($lines) => LogEntry::fromLines($lines));
}

@JosephSilber JosephSilber force-pushed the skip-until-skip-while branch from d8d66d0 to 06e1f5c Compare May 4, 2020 16:22
@JosephSilber JosephSilber force-pushed the skip-until-skip-while branch from 06e1f5c to 666ac7f Compare May 4, 2020 16:23
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