New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maybe add Iterables.concat(Iterator<? extends Iterable<? extends T>>) overload (returning Iterator) #627
Comments
Original comment posted by raymond.rishty on 2011-05-18 at 04:57 PM I think Iterables.concat (http://guava-libraries.googlecode.com/svn/tags/release09/javadoc/com/google/common/collect/Iterables.html#concat%28java.lang.Iterable%29) is what your looking for. See also, |
Original comment posted by raymond.rishty on 2011-05-18 at 04:58 PM If not, can you explain the situation where you have an Iterator but not an Iterable? |
Original comment posted by adam.g...@evocatus.com on 2011-05-18 at 06:05 PM Sure I could use concat by abusing the Iterable contract and making a throw away Iterable. I'm using Iterators.partition to generate an on demand grouping of items that I then need to turn back into the iterator I want. My mind partition and flatten go hand and hand. The iterator I'm passing in is on demand and very big (million +). Its not like its hard to code this... I just would not have to do repeat this for all my projects. |
Original comment posted by kevinb@google.com on 2011-05-19 at 02:10 AM I think this request makes sense, especially since it's our own Iterators.partition() method that returns this beast in the first place. Status: |
Original comment posted by kevinb@google.com on 2011-05-19 at 02:11 AM For now, the workaround is to transform the outer Iterator with a Function<Iterable, Iterator> that calls .iterator(), then concat that. |
Original comment posted by adam.g...@evocatus.com on 2011-05-19 at 03:04 AM @kevinb I agree with your solution (I think its what I even used). I only like flatten because its some what brings back warm fuzzy feelings I have when I used Lisp/Scheme/Ocaml... ah the glory days of academic FP. |
Original comment posted by j...@nwsnet.de on 2011-05-19 at 07:59 AM Isn't Guava's raymond: I just recently found myself using the |
Original comment posted by raymond.rishty on 2011-05-19 at 10:35 AM @yo: That is a very good point. I can see |
Original comment posted by neveue on 2011-05-19 at 10:51 AM If you want to work with Iterables / Collections instead, you can use java.util.Arrays.asList(T... a), which create a list backed by the given array. There is no instantiation overhead (since the List is a "view" of the source array). It lets you work with more powerful data-structures :) Other interesting methods:
|
Original comment posted by j...@nwsnet.de on 2011-05-19 at 05:22 PM nev: Thanks for the pointer. I tend to forget about |
Original comment posted by kevinb@google.com on 2011-07-13 at 06:18 PM (No comment entered for this change.) Status: |
Original comment posted by kevinb@google.com on 2011-07-13 at 07:19 PM (No comment entered for this change.) Status: |
Original comment posted by kevinb@google.com on 2011-07-13 at 07:27 PM (No comment entered for this change.) Labels: |
Original comment posted by kevinb@google.com on 2011-10-05 at 05:02 AM (No comment entered for this change.) Labels: |
Original comment posted by wasserman.louis on 2011-10-18 at 11:22 PM Should I do this? |
Original comment posted by kevinb@google.com on 2011-10-20 at 06:16 AM Sure, that'd be great. |
Original comment posted by yrfselrahc on 2011-12-05 at 06:35 PM (No comment entered for this change.) Labels: - |
Original comment posted by fry@google.com on 2011-12-10 at 04:09 PM (No comment entered for this change.) Labels: |
Original comment posted by kevinb@google.com on 2012-03-16 at 09:54 PM Oh crud. This method can't be added to Iterators. It's not a valid overload after erasure. It could be added to Iterables, but that's not where I'd have expected to see it at all. It would be the only method of Iterables to return Iterator. Is it worth doing that? |
Original comment posted by j...@nwsnet.de on 2012-03-17 at 12:30 PM If type erasure prohibits overloading, adding it under a different name would work. That also comes with a price tag, though. That said, I'm currently not into this issue, so it's neither a +1 nor -1 from me. |
Original comment posted by wasserman.louis on 2012-03-17 at 07:39 PM Iterators.concatIterables? |
Original comment posted by kevinb@google.com on 2012-05-30 at 07:43 PM (No comment entered for this change.) Labels: - |
Original issue created by adam.g...@evocatus.com on 2011-05-18 at 04:17 PM
I routinely need to do something like
public static <T> Iterator<T> flatten(final Iterator<? extends Iterable <T>> it);
In other words flatten an iterator of collection like objects.
It would be nice to have this in com.google.common.collect.Iterators
The text was updated successfully, but these errors were encountered: