Skip to content

Instantly share code, notes, and snippets.

@tjdevries
Last active February 5, 2023 21:36
Show Gist options
  • Save tjdevries/3deb5a697c5faa0a7d0bf8d82c6084ba to your computer and use it in GitHub Desktop.
Save tjdevries/3deb5a697c5faa0a7d0bf8d82c6084ba to your computer and use it in GitHub Desktop.
use std::env;
use std::fs;
fn main() -> Result<(), std::io::Error> {
let name = env::args().nth(1).expect("to pass an argument");
// Version 1
fs::read_to_string(&name)?
.lines()
.flat_map(|x| x.parse::<i32>())
.for_each(|x| println!("{x:?}"));
// Version 2, I kind of like passing func directly
fs::read_to_string(&name)?
.lines()
.flat_map(str::parse::<i32>)
.for_each(|x| println!("{x:?}"));
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment