Created
January 10, 2020 21:54
-
-
Save rust-play/24344d170ac0004fc57affab8dc93dc4 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or 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 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