Skip to content
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

Please explain why Lists doesn't have filter method #505

Closed
gissuebot opened this issue Oct 31, 2014 · 8 comments

Comments

Projects
None yet
1 participant
@gissuebot
Copy link

commented Oct 31, 2014

Original issue created by koppernickus on 2010-12-27 at 07:51 AM


I can see in idea graveyard that Lists.filter is one of rejected ideas. Could you please explain there why?

My motivation for Lists.filter is the need for transforming Iterable to List when using existing code requiring List as input. It would be more readable to use Lists.filter() instead of Lists.newArrayList(Collections2.filter())...

@gissuebot

This comment has been minimized.

Copy link
Author

commented Oct 31, 2014

Original comment posted by neveue on 2010-12-30 at 11:45 PM


Hey koppernickus,

This was already discussed in the google-collections issues / group, but your question is legitimate since there is no mention of it in the guava project's issues / group ;)

Guava does not provide such a method, because the filtered List view would have very poor performance.
They could have Lists.filter() return a filtered copy instead, but:

  • it would be counter-intuitive, since the similarly named Collections2.filter() and Iterables.filter() both returns views instead of copies
  • there is the problem of the choice of the List implementation to return: should we return an ArrayList? an ImmutableList? a LinkedList?

For these reasons, it is preferable to let the developer do the copy himself:
ImmutableList.copyOf(Iterables.filter())
Lists.newArrayList(Iterables.filter(
))
...

If you really want the syntactical sugar, and you know which implementation type you want to use in your project, you could create a static utility method that hides this boilerplate.

More info:
http://code.google.com/p/google-collections/issues/detail?id=7#c2
http://code.google.com/p/google-collections/issues/detail?id=98#c1
http://groups.google.com/group/google-collections-users/browse_thread/thread/2f0120513488977e
http://groups.google.com/group/google-collections-users/browse_thread/thread/5ade208a52ee3973
http://groups.google.com/group/google-collections-users/msg/fac903c3a542d77f

@gissuebot

This comment has been minimized.

Copy link
Author

commented Oct 31, 2014

Original comment posted by neveue on 2010-12-31 at 12:15 AM


Woops, just saw the related thread in the Google Group. It seems like you already knew all of this...

Anyway, I'll link it here, since it's related:
http://groups.google.com/group/guava-discuss/browse_thread/thread/278dd6a99214d91a

@gissuebot

This comment has been minimized.

Copy link
Author

commented Oct 31, 2014

Original comment posted by boppenheim@google.com on 2010-12-31 at 04:54 AM


Seems like the question has been sufficiently answered.


Status: WontFix

@gissuebot

This comment has been minimized.

Copy link
Author

commented Oct 31, 2014

Original comment posted by koppernickus on 2010-12-31 at 09:57 AM


Thanks for explanation, but what I really meant was explaining it on Wiki.
Most of the users don't read forum, they just go to Wiki pages. If you put
link to this thread in this page
http://code.google.com/p/guava-libraries/wiki/IdeaGraveyard I would be happy
:-)

@gissuebot

This comment has been minimized.

Copy link
Author

commented Oct 31, 2014

Original comment posted by boppenheim@google.com on 2010-12-31 at 06:47 PM


Great idea, its done.

@gissuebot

This comment has been minimized.

Copy link
Author

commented Oct 31, 2014

Original comment posted by wasserman.louis on 2011-12-28 at 05:55 PM


Issue #848 has been merged into this issue.

@gissuebot

This comment has been minimized.

Copy link
Author

commented Oct 31, 2014

Original comment posted by wasserman.louis on 2012-04-04 at 02:04 PM


Issue #958 has been merged into this issue.

@gissuebot

This comment has been minimized.

Copy link
Author

commented Oct 31, 2014

Original comment posted by cgdecker on 2012-04-04 at 03:20 PM


Issue #959 has been merged into this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.