+// You can change `main` to call this function, and you should notice - nothing, no difference in behavior.
+// But we wrote much less boilerplate code!
+
+// Remember that we decided to use the `FnMut` trait above? This means our closure could actually mutate its environment.
+// For example, we can use that to count the digits as they are printed.
+pub fn print_and_count(b: &BigInt) {
+ let mut count: usize = 0;
+ b.act(|digit| { println!("{}: {}", count, digit); count = count +1; } );
+ println!("There are {} digits", count);
+}
+
+// ## Fun with iterators and closures
+
+// Let's say we want to write a function that increments every entry of a `Vec` by some number, then looks for numbers larger than some threshold, and prints them.
+fn inc_print_even(v: &Vec<i32>, offset: i32, threshold: i32) {
+ for i in v.iter().map(|n| *n + offset).filter(|n| *n > threshold) {
+ println!("{}", i);
+ }
+}
+
+// Sometimes it is useful to know both the position of some element in a list, and its value. That's where the `enumerate` function helps.
+fn print_enumerated<T: fmt::Display>(v: &Vec<T>) {
+ for (i, t) in v.iter().enumerate() {
+ println!("Position {}: {}", i, t);
+ }
+}
+
+// And as a final example, one can also collect all elements of an iterator, and put them, e.g., in a vector.
+fn filter_vec_by_divisor(v: &Vec<i32>, divisor: i32) -> Vec<i32> {
+ unimplemented!()
+}
+
+// **Exercise 10.1**: Look up the [documentation of `Iterator`](https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html) to learn about more functions
+// that can act on iterators. Try using some of them. What about a function that sums the even numbers of an iterator? Or a function that computes the
+// product of those numbers that sit at odd positions? A function that checks whether a vector contains a certain number? Whether all numbers are
+// smaller than some threshold? Be creative!