method iter.inspect
Calls f on a copy of every element as it passes (debugging aid).
Example:
fn main() io {
let sum = [1, 2, 3].iter().inspect(x => print("saw {x}")).map(x => x * 2).collect()
print("{sum}")
}Output
saw 1 saw 2 saw 3 [2, 4, 6]
pub(api) move fn inspect<effect F>(f: fn(T) F escaping) -> iter<T> FComplexity. O(1) per element.
Since. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
f | fn(T) F escaping |
Returns
iter<T> F
Effects
none declared (pure unless the body says otherwise)
Defined in: std/core/iter.oxl:375