Skip to content

[Console] Add an iterate method to the ProgressBar class #29753

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 1 commit into from
Jan 31, 2019

Conversation

jvasseur
Copy link
Contributor

@jvasseur jvasseur commented Jan 2, 2019

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR symfony/symfony-docs#10949

Add an iterate method to the ProgressBar class that simplify updating the progress bar when iterating over an iterable.

Before:

$bar->start();
foreach ($iterable as $value) {
    // Process $value

    $bar->advance();
}
$bar->finish();

After:

foreach ($bar->iterate($iterable) as $value) {
    // Process $value
}

Additionally if $iterable is countable, the progress bar max step will automatically set to its count. If it isn't countable, nothing is done (instead of setting it to 0) to allow passing a max independently before calling iterate.

I will try to do the doc PR soon.

@jvasseur
Copy link
Contributor Author

jvasseur commented Jan 3, 2019

Updated the code to allow passing $max as a second argument instead of allowing to set the max before calling iterate.

@chalasr
Copy link
Member

chalasr commented Jan 31, 2019

Thank you @jvasseur.

@chalasr chalasr merged commit eb35531 into symfony:master Jan 31, 2019
chalasr pushed a commit that referenced this pull request Jan 31, 2019
…ss (jvasseur)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Console] Add an iterate method to the ProgressBar class

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        | symfony/symfony-docs#10949

Add an iterate method to the `ProgressBar` class that simplify updating the progress bar when iterating over an `iterable`.

Before:
```php
$bar->start();
foreach ($iterable as $value) {
    // Process $value

    $bar->advance();
}
$bar->finish();
```

After:
```php
foreach ($bar->iterate($iterable) as $value) {
    // Process $value
}
```

Additionally if `$iterable` is countable, the progress bar max step will automatically set to its count. If it isn't countable, nothing is done (instead of setting it to 0) to allow passing a max independently before calling `iterate`.

I will try to do the doc PR soon.

Commits
-------

eb35531 Add an iterate method to the ProgressBar class
@jvasseur jvasseur deleted the progress-iterate branch January 31, 2019 10:25
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Feb 1, 2019
… method (jvasseur)

This PR was merged into the master branch.

Discussion
----------

[Console] Add documentation for the ProgressBar::iterate method

Doc PR for symfony/symfony#29753

Commits
-------

5c0b716 [Console] Add documentation for the ProgressBar::iterate method
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
@fabpot fabpot mentioned this pull request May 9, 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.

6 participants