Giter Site home page Giter Site logo

iter_columns's Introduction

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.

[dependencies]
iter_columns = { version = "0.3.0", features = ["array_into_iter"] }

Examples

Consistent column length

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::<Vec<_>>(), [
        [1, 4],
        [2, 5],
        [3, 6],
    ]);
}

Inconsistent column length

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<_>>(), [
        vec![&1, &4],
        vec![&2, &5],
        vec![&6],
    ]);
}

Alternative for inconsistent column length

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<_>>(), [
        vec![Some(1), Some(4)],
        vec![Some(2), Some(5)],
        vec![None, Some(6)],
    ]);
}

iter_columns's People

Contributors

linus789 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.