Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::{thread, time};
- fn expensive_function() -> Vec<u64> {
- thread::sleep(time::Duration::from_secs(5));
- vec![4, 5, 6]
- }
- pub fn main() {
- let nums = [1, 2, 3];
- for &i in nums.iter().chain(expensive_function().iter()) {
- if i > 2 {
- break;
- } else {
- println!("{}", i);
- }
- }
- }
- let nums = [1, 2, 3];
- for i in nums.iter()
- .cloned()
- .chain([()].into_iter().flat_map(|_| expensive_function()))
- {
- if i > 2 {
- break;
- } else {
- println!("{}", i);
- }
- }
Add Comment
Please, Sign In to add comment