jroid8@lemmy.world to Programmer Humor@lemmy.ml · 11 months agoknow the features of your languagelemmy.worldimagemessage-square146fedilinkarrow-up1647arrow-down124cross-posted to: [email protected]
arrow-up1623arrow-down1imageknow the features of your languagelemmy.worldjroid8@lemmy.world to Programmer Humor@lemmy.ml · 11 months agomessage-square146fedilinkcross-posted to: [email protected]
minus-squarewords_numberlinkfedilinkarrow-up2·11 months agoI think you could even get rid of the iter() and the collect() since it’s a small fixed size array.
minus-squarebarsoap@lemm.eelinkfedilinkarrow-up2·edit-211 months agoYep [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.
I think you could even get rid of the
iter()
and thecollect()
since it’s a small fixed size array.Yep
[T;N]
has a direct implementation ofmap
."{:?}"
is necessary because arrays aren’tDisplay
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.