danielhenrymantilla / lending-iterator.rs

Lending iterators on stable Rust
https://docs.rs/lending-iterator
Apache License 2.0
80 stars 4 forks source link

filter_map behaves differently from Iterator #17

Open jonathan-conder opened 8 months ago

jonathan-conder commented 8 months ago

It seems like filter_map stops after the first None.

For example:

use ::lending_iterator::prelude::*;

fn main() {
    let array = [0, 1, 2, 3, 4, 5, 6];

    for m in array.iter().filter_map(|n| (n % 2 == 0).then_some(n)) {
        print!("{m} ");
    }
    println!();

    let iter = lending_iterator::from_iter(array.iter());
    let mut filtered = iter.filter_map_to_ref(|[], n| (n % 2 == 0).then_some(n));
    while let Some(m) = filtered.next() {
        print!("{m} ");
    }
    println!();
}

This prints:

0 2 4 6 
0 

I'm using version 0.1.7.