Last active
February 5, 2023 21:36
-
-
Save tjdevries/3deb5a697c5faa0a7d0bf8d82c6084ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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