4 ms·
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.
by cup-of-tea 9y ago
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.
- danieldk 9y agoThe itertools crate has you covered: https://docs.rs/itertools/0.7.8/itertools/fn.zip.html 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#75-80 https://docs.rs/itertools/0.7.8/src/itertools/free.rs.html#7...
- Rusky 9y agoThere's also UFCS: for (a, b) in Iterator::zip(as, bs) { // ... }
- coldtea 9y ago>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...
- cup-of-tea 9y agoBecause 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.
- coldtea 9y ago>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).