Closed GoogleCodeExporter closed 9 years ago
Thanks for the suggestions.
We decided against including a list-filtering method, for the the following
reasons.
The most commonly used features of a list, compared to an arbitrary collection,
are a
well-defined iteration ordering and random access by index.
Collections2.filter()
already keeps the iteration order of the provided collection. Retrieving a
value from
a filtered list by index is slow, since an iteration across the list, up to the
desired index, is needed. Between the possibility of slow performance and the
complexity of a filtered list implementation, it seemed better to omit the
method.
Collections.filter(list, predicate) or
Lists.newArrayList(Iterators.filter(list.iterator(), predicate)) would be better
solutions in most situations.
Regarding reduce, my main concern is that functional programming is generally so
verbose in Java, making simple iteration logic better in most cases, at least
for an
arbitrary reduction function. I'm not convinced that an arbitrary reduce method
would
make the calling code more readable. Now, some of our methods, such as
Ordering.max(E, E, E, E...) may be viewed as reduces with a fixed composition
function, and additional methods of that sort might be worthwhile.
Your Lists.removeByIndex() idea is plausible. However, when considering the
code I've
written or reviewed, I can't think of any cases when such a method would have
been
useful. Do other people think that such a method would be called sufficiently
often
to justify adding it to the library?
Original comment by jared.l....@gmail.com
on 15 Oct 2008 at 6:19
We won't add any of the proposed methods to the library, since they probably
wouldn't
be called sufficiently often.
Original comment by jared.l....@gmail.com
on 17 Oct 2008 at 6:26
Issue 276 has been merged into this issue.
Original comment by cpov...@google.com
on 26 Oct 2009 at 6:01
>> We won't add any of the proposed methods to the library, since they probably
wouldn't
be called sufficiently often.
What is the problem of having 3 methods making the library complete?
How have you decided that the number of use cases is small? How have you count
opinions?
Right now I have to code it myself. And the bigger disappointment is that even I
spend not too much time for coding in general my code won't be STABLE initially.
Please fix this. You have to help people to have complete tool even if some
part of
it are not perfect. Let army of google-collect consumers decide what to employ.
Don't
decide instead of us.
Original comment by koval...@gmail.com
on 28 May 2010 at 10:52
I can't say how common this is, but I needed it. I used
"Lists.newArrayList(Iterators.filter(list.iterator(), predicate))" mentioned
above. Eventually, I wound up here, because I couldn't believe that the
solution I found was the best way.
Original comment by curt...@gmail.com
on 15 Dec 2010 at 10:35
I'd like to add my support for a reduce function. The argument that functional
programming in Java is too verbose is applies equally to the transform method
but that exists and I use it all the time as I would a reduce method. I agree
that the library just seems incomplete without it
Original comment by rupert.b...@guardian.co.uk
on 17 Jun 2011 at 10:19
It's interesting to me that the WontFix is because of perceived lack of use of
the functions considering that filtering through a list is a very common use
case of lists.
Original comment by chengt
on 29 Sep 2011 at 8:11
I would also like to see this.
PS, I found it very amusing that the post by Jared on 10/15/08 had:
"Lists.newArrayList(Iterators.filter(list.iterator(), predicate)) would be
better
solutions in most situations."
and then:
"... my main concern is that functional programming is generally so
verbose in Java..."
To summarize:
Functional programming being verbose is 'main concern' for why not to implement
new method -- suggests even more verbose syntax as workaround.
You could always just create the filter method and wrap the iterator solution
you suggested.
Original comment by john.hin...@gmail.com
on 22 Jan 2012 at 7:17
Original issue reported on code.google.com by
ricky.cl...@gmail.com
on 15 Oct 2008 at 8:19