Skip to content

Commit 7ab9205

Browse files
committed
Remove use of map in early vecs2 exercise
Students do not have the necessary knowledge at this point to understand what's happening with the iterator combinators. This topic is covered well by the dedicated exercises about iterators later. closes #2102
1 parent 2af9e89 commit 7ab9205

File tree

4 files changed

+5
-46
lines changed

4 files changed

+5
-46
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Unreleased
22

3+
### Changed
4+
5+
- `vecs2`: Removed the use of `map` and `collect`, which are only taught later.
6+
37
## 6.5.0 (2025-08-21)
48

59
### Added

exercises/05_vecs/vecs2.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,6 @@ fn vec_loop(input: &[i32]) -> Vec<i32> {
99
output
1010
}
1111

12-
fn vec_map_example(input: &[i32]) -> Vec<i32> {
13-
// An example of collecting a vector after mapping.
14-
// We map each element of the `input` slice to its value plus 1.
15-
// If the input is `[1, 2, 3]`, the output is `[2, 3, 4]`.
16-
input.iter().map(|element| element + 1).collect()
17-
}
18-
19-
fn vec_map(input: &[i32]) -> Vec<i32> {
20-
// TODO: Here, we also want to multiply each element in the `input` slice
21-
// by 2, but with iterator mapping instead of manually pushing into an empty
22-
// vector.
23-
// See the example in the function `vec_map_example` above.
24-
input
25-
.iter()
26-
.map(|element| {
27-
// ???
28-
})
29-
.collect()
30-
}
31-
3212
fn main() {
3313
// You can optionally experiment here.
3414
}

rustlings-macros/info.toml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,7 @@ of the Rust book to learn more."""
318318
name = "vecs2"
319319
dir = "05_vecs"
320320
hint = """
321-
In the first function, we create an empty vector and want to push new elements
322-
to it.
323-
324-
In the second function, we map the values of the input and collect them into
325-
a vector.
326-
327-
After you've completed both functions, decide for yourself which approach you
328-
like better.
329-
330-
What do you think is the more commonly used pattern under Rust developers?"""
321+
Use the `.push()` method on the vector to push new elements to it."""
331322

332323
# MOVE SEMANTICS
333324

solutions/05_vecs/vecs2.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@ fn vec_loop(input: &[i32]) -> Vec<i32> {
88
output
99
}
1010

11-
fn vec_map_example(input: &[i32]) -> Vec<i32> {
12-
// An example of collecting a vector after mapping.
13-
// We map each element of the `input` slice to its value plus 1.
14-
// If the input is `[1, 2, 3]`, the output is `[2, 3, 4]`.
15-
input.iter().map(|element| element + 1).collect()
16-
}
17-
18-
fn vec_map(input: &[i32]) -> Vec<i32> {
19-
// We will dive deeper into iterators, but for now, this is all what you
20-
// had to do!
21-
// Advanced note: This method is more efficient because it automatically
22-
// preallocates enough capacity. This can be done manually in `vec_loop`
23-
// using `Vec::with_capacity(input.len())` instead of `Vec::new()`.
24-
input.iter().map(|element| 2 * element).collect()
25-
}
26-
2711
fn main() {
2812
// You can optionally experiment here.
2913
}

0 commit comments

Comments
 (0)