On iterators

  1. Is there a plan for a shorter alternative to ‘Iterators.filter’ and the like? The ‘Iterators’ word takes quite a number of columns, especially if used multiple times.
  2. Why is it not allowed to use ‘takewhile’, ‘dropwhile’, and ‘countfrom’ without ‘Iterators’, like ‘enumerate’? Possible conflict?
  3. Would it be possible to add something like ‘1:_’ as an alternative to ‘countfrom’?
  4. No plan for ‘Iterators.map’?
  1. Not really. Base already has a filter function, which is eager instead of lazy. One could of course add an alias, but just saving a handful of characters might not be worth adding another export to Base for. You could always do, e.g. const ifilter = Iterators.filter on top of your own code to have a shorter alias.
  2. Similar argument to above, but those names could potentially be exported. I am just not 100% sure, they’re used that often in code to justify exporting them. Another advantage of having to be explicit about them being in the Iterators submodule is that it’s clear straightaway that they behave lazily to anyone looking at your code.
  3. Most likely not. The _ syntax has been proposed as syntax for creating anonymous functions, which I am pretty sure will be added to Julia eventually once all the details have been worked out. InfiniteArrays.jl exports ​∞, which is similar to what you are asking for.
  4. You are basically asking for generators (i.e. (f(i) for i in itr)), which you can also create directly with Base.Generator(f, itr). Iterators.map has actually been proposed as an alias here, so that might also make it into Base.
5 Likes

Note also that if you use dropwhile or other iterators a lot so that the Iterators. prefix becomes bothering, just do using Iterators: dropwhile, or simply using Iterators (which exports most of the iterators from that module).

2 Likes