Giter Site home page Giter Site logo

tupletools's Introduction

TupleTools

Provides utility functions like fst and snd. In development.

Works with #[no_std] !

Examples:

#[test]
fn fst() {
    let x = vec![(2, 3), (3, 4), (4, 5), (5, 6)];

    let expected = vec![2, 3, 4, 5];
    assert_eq!(x.iter().map(Fst::fst).cloned().collect::<Vec<_>>(), expected);
    assert_eq!(x.into_iter().map(fst).collect::<Vec<_>>(), expected);
}

#[test]
fn snd() {
    let x = vec![(2, 3), (3, 4), (4, 5), (5, 6)];

    let expected = vec![3, 4, 5, 6];
    assert_eq!(x.iter().map(Snd::snd).cloned().collect::<Vec<_>>(), expected);
    assert_eq!(x.into_iter().map(snd).collect::<Vec<_>>(), expected);
}

#[test]
fn sub() {
    let x = vec![(1, 2, 1), (1, 1, 1)];
    let y = (1, 1, 1);
    let z = (1, 1, 1);

    assert_eq!(y.sub(z), (0, 0, 0));

    assert_eq!(x.into_iter().fold((0, 0, 0), |a, b| a.sub(b)), (-2, -3, -2));
}

#[test]
fn div() {
    let x = vec![(1, 2, 1), (1, 1, 1)];
    let y = (1, 1, 1);
    let z = (1, 1, 1);

    assert_eq!(y.div(z), (1, 1, 1));

    assert_eq!(
        x.into_iter().fold((1, 1, 1), |a, b| a.div(b)),
        (1, 1 / 2, 1)
    );
}

#[test]
fn cast_one_to_one() {
    let x: (u32, u32, u32, u32, u32, u32) = (3, 4, 5, 6, 7, 8);
    let _z: (u64, u64, u64, u64, u64, u64) = x.cast();
}

tupletools's People

Contributors

sagebati avatar

Watchers

 avatar  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.