Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

They maybe rear their ugly head but they also allow you to collect the iterator into any collection written by you, by the standard library or by any other crate.

While in python you have list/dict/set/generator comprehension and that's it.



I don't think it's bad thing. In fact one of my favorite features is that you can do `.collect::<Result<Vec<_>, _>>()` to turn an interators of Results, into a Result of just the Vec if all items succeed or the first error. That is a feature you just can't express in Python.

But you have to admit that is a pretty noisy line that could be difficult to parse.


Then don't write it that way.

   let new_array: Vec<usize> = array.into_iter()
        .filter(|&x| x != 0)
        .map(|x| x * 2)
        .collect();
Isn't so bad.


I believe I have the habit of putting it on the end because the final type might be different. Consider:

    let array = ["DE", "AD", "BE", "EF"];
    let new_array: Vec<u32> = array.into_inter()
      .map(|x| u32::from_str_radix(x, 16))
      .collect()?;
In this case you need to specify the Result generic type on generic. This has come up for me when working with Stream combinators. Most projects probably end up in needing some lifetime'd turbofish and you have to be able to parse them. They aren't rare enough, IME, to argue that Rust isn't noisy.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: