Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created April 10, 2018 18:30
Show Gist options
  • Save rust-play/216716abf6f871e3efb69899898795f1 to your computer and use it in GitHub Desktop.
Save rust-play/216716abf6f871e3efb69899898795f1 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use std::iter::Iterator;
fn main() {
println!("Hello, world!");
other(stream(|| 1));
}
fn other(s: impl Iterator<Item = i32> +'static) -> impl Iterator<Item = i32> + 'static {
s
}
fn stream(supplier: impl Fn() -> i32) -> impl Iterator<Item = i32> {
let items = vec![1, 2, 3];
items.into_iter()
.map(move |n| n + supply(&supplier))
}
fn supply(supplier: impl Fn() -> i32) -> i32 {
supplier()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment