Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created January 10, 2020 21:54
Show Gist options
  • Save rust-play/24344d170ac0004fc57affab8dc93dc4 to your computer and use it in GitHub Desktop.
Save rust-play/24344d170ac0004fc57affab8dc93dc4 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use core::iter::once;
fn main() {
println!("{:?}", fmap(|x| x + 1, 1..100000));
}
fn fmap<A, B>(f: impl Fn(A) -> B, mut foo: impl Iterator<Item=A>) -> Vec<B> {
match foo.next() {
Some(x) => once(f(x)).chain(fmap(f, foo)).collect(),
None => Vec::new()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment