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
let a = ["1","2","lol"];letmut iter = a.iter().filter_map(|s| s.parse().ok());assert_eq!(iter.next(),Some(1));assert_eq!(iter.next(),Some(2));assert_eq!(iter.next(),None);
I find it a bit misleading that there are 3 array elements and 3 asserts that do not correspond in the obvious way. It is too easy to skim this and interpret it as:
let a = ["1","2","lol"];letmut iter = a.iter().map(|s| s.parse().ok());assert_eq!(iter.next().unwrap(),Some(1));assert_eq!(iter.next().unwrap(),Some(2));assert_eq!(iter.next().unwrap(),None);
I think using ["1", "lol", "3", "NaN", "5"] with four asserts would avoid the confusion.
The text was updated successfully, but these errors were encountered:
dtolnay
added
the
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
label
Dec 14, 2017
This is the example currently given for
Iterator::filter_map
:I find it a bit misleading that there are 3 array elements and 3 asserts that do not correspond in the obvious way. It is too easy to skim this and interpret it as:
I think using
["1", "lol", "3", "NaN", "5"]
with four asserts would avoid the confusion.The text was updated successfully, but these errors were encountered: