https://github.com/linus789/iter_columns
https://github.com/linus789/iter_columns
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/linus789/iter_columns
- Owner: Linus789
- License: apache-2.0
- Created: 2021-05-28T16:14:30.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-01T21:33:00.000Z (about 5 years ago)
- Last Synced: 2025-04-28T11:22:08.898Z (about 1 year ago)
- Language: Rust
- Homepage: https://crates.io/crates/iter_columns
- Size: 19.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# iter_columns
Iterate over columns easily.
Works with Vecs, Slices and Arrays.
The support for `std::array::IntoIter` is disabled by default
and is only available for Rust versions since (>=) 1.51.0.
To enable the support, use the `array_into_iter` feature.
```toml
[dependencies]
iter_columns = { version = "0.3.0", features = ["array_into_iter"] }
```
## Examples
### Consistent column length
```rust
use iter_columns::prelude::*;
fn main() {
let test_data = vec![
vec![1, 2, 3],
vec![4, 5, 6],
];
assert_eq!(test_data.into_iter().columns().collect::>(), [
[1, 4],
[2, 5],
[3, 6],
]);
}
```
### Inconsistent column length
```rust
use iter_columns::prelude::*;
fn main() {
let test_data = vec![
vec![1, 2], // 2 columns
vec![4, 5, 6], // 3 columns
];
// you can also use iter() or iter_mut() instead of into_iter()
assert_eq!(test_data.iter().columns().collect::>(), [
vec![&1, &4],
vec![&2, &5],
vec![&6],
]);
}
```
### Alternative for inconsistent column length
```rust
use iter_columns::prelude::*;
fn main() {
let test_data = vec![
vec![1, 2],
vec![4, 5, 6],
];
// use columns_options() instead of columns()
assert_eq!(test_data.into_iter().columns_options().collect::>(), [
vec![Some(1), Some(4)],
vec![Some(2), Some(5)],
vec![None, Some(6)],
]);
}
```