Browse Source

1460-DEV-3511 feat(iterators): improve consistency and clarity

dquote>
dquote> now the iterator trait is well implemented and tested and collatz() return value in line with idiomatic rust
first example formatting is clearer
provided testing main() has also edge cases 0 and 1
pull/1474/head^2
Michele Sessa 2 years ago committed by Michele
parent
commit
28bccd6e59
  1. 38
      subjects/iterators/README.md

38
subjects/iterators/README.md

@ -19,11 +19,11 @@ Examples:
Starting with n = 16, the steps would be as follows: Starting with n = 16, the steps would be as follows:
0- 16 0. 16
1- 8 1. 8
2- 4 2. 4
3- 2 3. 2
4- 1 4. 1
Resulting in 4 steps. So for input n = 16, the return value would be 4. Resulting in 4 steps. So for input n = 16, the return value would be 4.
@ -35,14 +35,18 @@ Resulting in 4 steps. So for input n = 16, the return value would be 4.
### Expected functions ### Expected functions
```rust ```rust
#[derive(Copy, Clone)]
struct Collatz { pub struct Collatz {
v: u64, pub v: u64,
} }
impl Iterator for Collatz {} impl Iterator for Collatz {}
pub fn collatz(n: u64) -> Option<u64> {} impl Collatz {
pub fn new(n: u64) -> Self {}
}
pub fn collatz(n: u64) -> usize {}
``` ```
### Usage ### Usage
@ -53,6 +57,8 @@ Here is a program to test your function.
use iterators::*; use iterators::*;
fn main() { fn main() {
println!("{:?}", collatz(0));
println!("{:?}", collatz(1));
println!("{:?}", collatz(4)); println!("{:?}", collatz(4));
println!("{:?}", collatz(5)); println!("{:?}", collatz(5));
println!("{:?}", collatz(6)); println!("{:?}", collatz(6));
@ -65,10 +71,12 @@ And its output:
```console ```console
$ cargo run $ cargo run
Some(2) 0
Some(5) 0
Some(8) 2
Some(16) 5
Some(9) 8
16
9
$ $
``` ```

Loading…
Cancel
Save