let count = input
.iter()
.fold(0, |acc, item| if predicate(&item) { acc + 1 } else { acc });
However, I feel like this is a fairly common goal and I might be overcomplicating it. Is there something in the stdlib that allows doing the above with an interface that is closer to this?
let count = input
.iter()
.count_if(|item| predicate(&item));
Thanks! That indeed works and much nicer to read. For the record, I benchmarked both solutions (predicate and data being the same) and found that both performed roughly the same (within .1 ms of each other per run).