IterTools.jl icon indicating copy to clipboard operation
IterTools.jl copied to clipboard

Import Base.Iterators when IterTools is used

Open rapus95 opened this issue 7 years ago • 10 comments

If possible it would be nice if Base.Iterators-functions were imported automatically for cleaner code. Since lines like collect(Iterators.flatten(chain(1:9,reverse(11:20),10) would look cleaner if it was just flatten rather than Iterators.flatten. When people import IterTools it seems to be clear that they intend to use them (alot) or like to go for functional programming and thus simplifying it sounds like a good idea to me.

rapus95 avatar Mar 28 '18 14:03 rapus95

We can probably do this with @reexport using Base.Iterators.

ararslan avatar Mar 28 '18 19:03 ararslan

We'll have to be more careful than that. There would be conflicts. But we should just clear up those conflicts I think.

iamed2 avatar Mar 29 '18 12:03 iamed2

I think this is a good idea, and that we should also import the documentation for it too.

Then one would only need to look in Itertools, rather than Itertools and Base.Iterators when looking for a particular set of functionality.

oxinabox avatar Jan 09 '19 14:01 oxinabox

Conflicts between Iterators and IterTools were cleared up.

We can do this, but we won't be able to export everything (e.g., we can't export filter as it's different than Base.filter).

iamed2 avatar Jan 09 '19 14:01 iamed2

Can we export those things as ifilter to match to imap etc?

oxinabox avatar Jan 09 '19 14:01 oxinabox

Are there any news on this?

rapus95 avatar Oct 09 '19 12:10 rapus95

It is still desired but noone has gotten round to it. It is a simple but mildly long PR if you are interested

oxinabox avatar Oct 09 '19 13:10 oxinabox

@oxinabox what would I have to change?

rapus95 avatar Oct 09 '19 15:10 rapus95

Add to the exports:

export ifilter, # etc

add to the code:

const ifilter = Iterators.filter
#etc

List of all of them is

 countfrom
 cycle
 drop
 flatten
 partition
 product
 repeated
 rest
 take

Working out which should be prefixed with i is the hard part. Filter definately should. The others? idk

oxinabox avatar Oct 09 '19 20:10 oxinabox

In my opinion we should either rename as few as necessary (thus only changing filter to ifilter) or switching all functions to a prefix i version, including the functions of IterTools.

Strategy A: Backwards Compatibility first Pro : Full backwards compatibility while the lazy filter function only gets an additional name. Con: Feels inconsistent

Strategy B: Consistency first As for Strategy A but switched and negated. In the long run this might help whenever Julia decides to switch to an Iterator-first or a Materialize-first manner.

rapus95 avatar Oct 10 '19 06:10 rapus95