铁 rust 相当于tap()是多少?
它对迭代器中的每个项调用一个函数,如map()
,但tap()
返回的不是函数返回的值,而是原始项.
例如,我想以某种方式在中途拨打println!()
:
foo.into_iter()
.filter(|x| x == target)
.tap(|x| println!("{:?}", x)) // <-- what goes here?
.map(|c| c.result)
更正:
tap()
calls the closure once on the entire iterator
inspect()
calls the closure on each item in the iterator