You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apparently iter::Map and iter::Filter implement DoubleEndedIterator. This could lead to unexpected behavior:
let counter = iter::repeat(()).map({
let mut ctr = 0;
move |_| {
ctr += 1;
ctr
}
});
let counter2 = counter.reverse(); // Doesn't reverse anything.
These adapters are only really reversible when passed closure is side-effect free. Unfortunately, we can't simply say that map calls the passed closure on each element yielded because counter.last() != counter.reverse().next().
Activity
steveklabnik commentedon Dec 31, 2015
/cc @rust-lang/libs
Kimundi commentedon Jan 1, 2016
I don't think we need to change anything here apart from maybe improving the docs by pointing out this pitfall.
The behavior of
last(),reverse()etc is well specified, so different behavior if combined with side-effecting closures should be too.Rollup merge of rust-lang#31220 - steveklabnik:gh30632, r=nikomatsakis
Add note about side effects to Filter docs