Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. use std::cell::Cell;
  2.  
  3. fn main() {
  4. let c = &Cell::new(10);
  5. let it = std::iter::from_fn(|| {
  6. let x = c.get();
  7. if x == 0 {
  8. None
  9. } else {
  10. c.set(x - 1);
  11. Some(x)
  12. }
  13. });
  14. let it = it.cycle();
  15. it.for_each(|x| {
  16. dbg!(x);
  17. });
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement