Created
April 10, 2018 18:30
-
-
Save rust-play/216716abf6f871e3efb69899898795f1 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains 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 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