# for_each_count
Extremely simple crate providing an extension trait for the standard [Iterator] trait
with two utility methods:
- [`for_each_count`]: Similar to [`for_each()`] but returns the count of processed elements
- [`try_for_each_count`]: Similar to [`try_for_each()`] but returns the count of processed elements in the [`Ok`] case.
Both methods solve the *common*[^2] use case of applying a transformation to iterator elements and then returning the length of the iterator.
While this is trivial to achieve using the standard methods[^1], I find these extension methods to be more ergonomic, and they are available in the big extension crates, like `Itertools`.
The provided extension methods try to mimic the way they'd be _likely_ implemented in core: based on [`fold()`] and [`try_fold()`].
This seems to be the preferred strategy in the standard library. [`for_each()`], [`try_for_each()`] and [`count()`] are all implemented like this at this time.
[Other people too]: <https://stackoverflow.com/questions/73842276/how-to-for-each-and-then-count-them-in-rust>
[`for_each_count`]: IteratorForEachCount::for_each_count
[`try_for_each_count`]: IteratorForEachCount::try_for_each_count
[`for_each()`]: Iterator::for_each
[`try_for_each()`]: Iterator::try_for_each
[`count()`]: Iterator::count
[`fold()`]: Iterator::fold
[`try_fold()`]: Iterator::try_fold
## Examples
```rust
use for_each_count::IteratorForEachCount;
let mut sum = 0;
assert_eq!(sum, 15);
```