1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use Debug;
/// Returns the flattened version of the input.
///
/// Takes a list of nested items as a reference and returns the flattened version of it.
///
/// Basic usage:
/// ```
/// use algorithmz::array::{Nested, flatten};
/// let input = vec![Nested::Item(2),Nested::List(vec![Nested::Item(3),Nested::Item(5)])];
/// let result = flatten(&input).unwrap();
/// assert_eq!(result,vec![2,3,5]);
/// ```
///
/// Usage with match statement:
/// ```
/// use algorithmz::array::{flatten, Nested};
/// let input = vec![Nested::Item(2),Nested::List(vec![Nested::Item(3),Nested::Item(5)])];
/// match flatten(&input) {
/// Err(e) => eprintln!("The error was: {}",e),
/// Ok(n) => println!("The flattened list: {:?}",n),
/// }
/// ```
/// The enum representing a multi dimensional array
///
/// # Examples
///
/// Simple nested list of values
/// ```
/// use algorithmz::array::Nested;
/// let input = vec![Nested::Item(10),Nested::Item(20)];
/// ```
///
/// Nested lists:
/// ```
/// use algorithmz::array::Nested;
/// let input = Nested::List(vec![Nested::Item(10),Nested::List(vec![Nested::Item(20),Nested::Item(30)])]);
/// ```
/// The private helper function