Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Rust

Idiom #258 Convert list of strings to list of integers

Convert the string values from list a into a list of integers b.

let b: Vec<i32> = a.iter().flat_map(|s| s.parse().ok()).collect();

ok converts a Result to an Option. flat_map collects all values of Some.
let b: Vec<i64> = a.iter().map(|x| x.parse::<i64>().unwrap()).collect();

a has type Vec<&str>
System.Linq;
var b = a.Select(i => int.Parse(i)).ToList();

New implementation...