Skip to content

Instantly share code, notes, and snippets.

@ROki1988
Created October 24, 2020 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ROki1988/8b60d26282f4ad6241ee77dd2da6935b to your computer and use it in GitHub Desktop.
Save ROki1988/8b60d26282f4ad6241ee77dd2da6935b to your computer and use it in GitHub Desktop.
sliding
use std::env::{args, args_os};
use std::io;
use std::io::Read;
/// $ seq 1 4 | sliding
/// > 1 2
/// > 2 3
/// > 3 4
fn main() -> Result<(), io::Error> {
let d = args().enumerate().find(|(_, x)| x == "-d").map_or_else(
|| " ".to_string(),
|(i, _)| {
args_os()
.nth(i + 1)
.expect("need value")
.to_str()
.unwrap()
.to_string()
},
);
let io = io::stdin();
let mut handle = io.lock();
let mut buff = String::new();
handle.read_to_string(&mut buff)?;
let iter = buff.lines().zip(buff.lines().skip(1));
for x in iter {
println!("{}{}{}", x.0, d, x.1);
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment