There is quite a number of crates implementing comprehension syntax (in the Miranda -> Haskell -> Python lineage):
and probably more.
Have you any experience with any of these?
Can you suggest how to choose between them, or recommend some over some others?
I'm the author of that one; I was quite pleased with the state of that crate at the time I wrote it, and would be willing to add features to it should somebody feel something is lacking (e.g., sugar for hashmaps as well, or some suffix
.map() adaptors rather than
iter!(…).map()). Other than that the macros are simple enough to write that any of these multiple implementations / crates ought to be trustworthy, I'd say. It may then be a matter of which comprehension syntax you are most used to and thus most comfortable reading / writing. I personally went with a huge Python bias, for instance
I personally like the fact my macros supported
if let Some(x) = elem clauses, with the new bindings available in the
<expr> part of the comprehension; I don't know if the others do.
It also comes with a nice lazy-formatting utility, should you be concerned about performance of "joining strings", for instance.
iter-python support Cartesian products (nested
For example, trying to reproduce this Python example
>>> [ x*y for x in range(3) for y in range(3) ]
[0, 0, 0, 0, 1, 2, 0, 2, 4]
vec![ x*y for x in (0..3) for y in (0..3) ];
gives this error:
10 | vec![ x*y for x in (0..3) for y in (0..3) ];
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`foo`)
= note: this error originates in the macro `$crate::vec_it` (in Nightly builds, run with -Z macro-backtrace for more info)
As of the latest release, it does (I've also take the chance to clean up the code and make sure the macro is readable; supporting comma-less syntax required some muching)
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.