Coder Social home page Coder Social logo

Comments (7)

bluss avatar bluss commented on July 19, 2024 2

Like in #151, I think for (fst, snd) in primes.iter().tuple_windows() can become a reality soon.

from itertools.

bluss avatar bluss commented on July 19, 2024 1

I don't think typenum supports tuples, or is the solution we want? We can do something simpler with traits. Should look at other cases like .combinations() as well as windows.

from itertools.

bluss avatar bluss commented on July 19, 2024

Needs to take into account that integer parameters like 2 are runtime information and tuple arity is type-level compile time information. Would work fine with a type-level kind of parameterization, either .windows2() or .windows::<Pair>() and so on.

from itertools.

Robbepop avatar Robbepop commented on July 19, 2024

Ah dang. You are right, I haven't thought about that. Maybe with the typenum crate one could work around this until associated constants land in Rust, if ever?

from itertools.

Robbepop avatar Robbepop commented on July 19, 2024

I do not know exactly how he did it, but in Crate: Generic Array the owner uses typenum::uint in order to create a generic statically sized array. This could be used in a similar way to create an easy-to-use windows(N) iterator that can have tuples (compile-time-constant size types) as iterator elements. =)
ArrayLength is where the magic happens according to the owner of the generic-array crate.

from itertools.

bluss avatar bluss commented on July 19, 2024

They use an interesting trick where they just make a struct of the correct size. Instead of [T; 4] they have struct { struct { T, T }, struct { T, T } }.

from itertools.

mmun avatar mmun commented on July 19, 2024

I was looking for this today and my gut reaction was to try

let primes = &[2, 3, 5, 7, 11, 13, 17, ...];
for (fst, snd) in iwindow!(primes.iter(), 2) {
    println!("({}, {})", fst, snd);
}

from itertools.

Related Issues (20)

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.