Coder Social home page Coder Social logo

Comments (7)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 29, 2024
List<Foo> list = Lists.filter(myList, myPredicate); would be nice too.

Original comment by [email protected] on 12 Oct 2007 at 9:04

from google-collections.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 29, 2024
Thanks for the suggestion.  Because we don't have a filtered List view, we 
recommend
that users who want a List result copy the data instead, by passing the result 
of
filter() to a List factory such as Lists.immutableList() or 
Lists.newArrayList().

If a filtered view of a List were produced, it would be Lists.filter().  
However,
unlike with Lists.transform(), here we have performance concerns.  The size(), 
get()
and indexOf() methods of the resulting list would all perform abysmally, and as 
these
methods are very fundamental to List behavior, you basically have an all-around
poorly-performing List.

So: are you sure you want it?  And if so, please hit me with those use cases!

Original comment by [email protected] on 12 Oct 2007 at 10:45

from google-collections.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 29, 2024
Wait, I misunderstood the original request.  My last answer addressed only gk's
add-on request.

The original request, now that I understand it, is really for just a wee bit of
syntactic sugar, which would, if applied consistently, end up greatly bloating 
the
size of the Iterators API.  As such, I'm against it.

Original comment by [email protected] on 12 Oct 2007 at 10:48

from google-collections.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 29, 2024
Fair enough.

Original comment by [email protected] on 12 Oct 2007 at 11:17

from google-collections.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 29, 2024

Original comment by [email protected] on 16 Oct 2007 at 3:55

  • Changed state: WontFix

from google-collections.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 29, 2024
yeah, i agree that the filtered view would be pretty unfortunate.  i was 
envisioning a copy.  really, the only 
reason that i want it would be because a lot of apis use Collection over 
Iterable (even though i agree that it's not 
necessary in a lot of situations) and i get sick of making new lists all the 
time.  like e.e. i just wanted the sugar.

Original comment by [email protected] on 19 Oct 2007 at 3:58

from google-collections.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 29, 2024
Gotcha.

One thing - while a filtered List view has significant problems, a filtered
Collection or Set view may not be so bad.  The worst that can be said of these 
is the
O(n) size() and isEmpty()... but "plenty" of other JDK collections have an O(n)
size()... so we might still do that.

As for copying, what our API wants to do as *little* as possible is to secretly
choose Collection implementation classes for you that *we* think will be good 
enough.
 So, the idiom to create a filtered copy of a set is either

  Set<String> filtered = Sets.newHashSet(Iterables.filter(set, predicate));

or

  Set<String> filtered = Sets.newTreeSet(Iterables.filter(set, predicate));

etc. etc.

Original comment by [email protected] on 19 Oct 2007 at 4:28

from google-collections.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.