Skip to content

Instantly share code, notes, and snippets.

@little-arhat
Created October 4, 2014 18:41
Show Gist options
  • Save little-arhat/88e34b5ccc0024a36a48 to your computer and use it in GitHub Desktop.
Save little-arhat/88e34b5ccc0024a36a48 to your computer and use it in GitHub Desktop.
#![feature(macro_rules)]
macro_rules! iter_magic(
($inp:expr => $($func:ident ($args:expr))=>+) => (
$inp.iter()$(.$func($args))+
);
)
fn main() {
let b = "hello".as_bytes();
for c in iter_magic!(b =>
map(|x| x) =>
filter(|&x| x % 2 == 0 )
) {
println!("{}", c);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment