Skip to content

Commit

Permalink
Add main method to code snippet (#2630)
Browse files Browse the repository at this point in the history
The code snippet wouldn't compile/run directly because of a missing
`main` method.

Also remove unnecessary `&`.
  • Loading branch information
randomPoison authored Feb 7, 2025
1 parent af6dff5 commit c05f0b6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/iterators/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ In addition to the `next` method that defines how an iterator behaves, the
customized iterators.

```rust,editable
let result: i32 = (1..=10) // Create a range from 1 to 10
.filter(|&x| x % 2 == 0) // Keep only even numbers
.map(|x| x * x) // Square each number
.sum(); // Sum up all the squared numbers
println!("The sum of squares of even numbers from 1 to 10 is: {}", result);
fn main() {
let result: i32 = (1..=10) // Create a range from 1 to 10
.filter(|x| x % 2 == 0) // Keep only even numbers
.map(|x| x * x) // Square each number
.sum(); // Sum up all the squared numbers
println!("The sum of squares of even numbers from 1 to 10 is: {}", result);
}
```

<details>
Expand Down

0 comments on commit c05f0b6

Please sign in to comment.