this post was submitted on 08 Dec 2023
623 points (96.4% liked)

Programmer Humor

32425 readers
917 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 11 months ago* (last edited 11 months ago)

Yep [T;N] has a direct implementation of map. "{:?}" is necessary because arrays aren't Display but you could get around that by saying

["1", "not a number", "3"].map(|n| println!("{}", n.parse().unwrap_or(0)));

but now I'm golfing. Also

for n in ["1", "not a number", "3"] {
   println!("{}", n.parse().unwrap_or(0))
}

is more idiomatic I shouldn't let my Haskell get the better of me. That does use Iterator, not that it makes a difference here.