Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The Rust version of "zip" seems a bit odd as it's implemented like a method rather than a function. Little things like make me not enjoy a language as much.


>as it's implemented like a method rather than a function

Why should it be a function? It can be a method on sequence like objects (trait)...

Python itself has tons of those...


Because the parameters to zip aren't positional, they are just multiple parameters of the same type.

Python does have some that annoy me a bit. I think str.join would be clearer as a function, but at least that does have a positional parameter.


>Because the parameters to zip aren't positional, they are just multiple parameters of the same type.

How is that a counter-argument? It makes sense then that the method belongs to that type (iteratables).


The itertools crate has you covered:

https://docs.rs/itertools/0.7.8/itertools/fn.zip.html

By the way, the Iterator's zip function is no magic. You could trivially implement a standalone function using the zip method yourself:

https://docs.rs/itertools/0.7.8/src/itertools/free.rs.html#7...


There's also UFCS:

    for (a, b) in Iterator::zip(as, bs) {
        // ...
    }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: