• words_number
    link
    fedilink
    arrow-up
    2
    ·
    1 year ago

    I think you could even get rid of the iter() and the collect() since it’s a small fixed size array.

    • barsoap@lemm.ee
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      1 year 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.