X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/b30edaca267b5900279eb43b5a70889899bad62d..a43cc90b79e0b17302c74982270e29a4b93f5f0f:/src/part10.rs?ds=inline diff --git a/src/part10.rs b/src/part10.rs index 02fb828..0522cb0 100644 --- a/src/part10.rs +++ b/src/part10.rs @@ -131,12 +131,12 @@ fn print_enumerated(v: &Vec) { // 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, divisor: i32) -> Vec { //@ Here, the return type of `collect` is inferred based on the return type of our function. In general, it can return anything implementing - //@ [`FromIterator`](http://doc.rust-lang.org/stable/std/iter/trait.FromIterator.html). Notice that `iter` gives us an iterator over + //@ [`FromIterator`](https://doc.rust-lang.org/stable/std/iter/trait.FromIterator.html). Notice that `iter` gives us an iterator over //@ borrowed `i32`, but we want to own them for the result, so we insert a `map` to dereference. v.iter().map(|n| *n).filter(|n| *n % divisor == 0).collect() /*@*/ } -// **Exercise 10.1**: Look up the [documentation of `Iterator`](http://doc.rust-lang.org/stable/std/iter/trait.Iterator.html) to learn about more functions +// **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!