Comments (7)
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.
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.
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.
Fair enough.
Original comment by [email protected]
on 12 Oct 2007 at 11:17
from google-collections.
Original comment by [email protected]
on 16 Oct 2007 at 3:55
- Changed state: WontFix
from google-collections.
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.
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)
- Preconditions.checkArgumentNotNull HOT 2
- MapMaker with weak keys: keySet() doubles reference counts in map HOT 4
- broken checksums in maven artefacts for rc4 HOT 6
- Predicates.equalTo() should return a Predicate<Object> HOT 2
- Make com.google.common.collect.ImmutableCollection.Builder public HOT 3
- Easy way to deal with null Iterables when looping HOT 1
- Please provide Sets.symmetricDifference() HOT 3
- static method Functions.toStringFunction() should be parametrized HOT 5
- LinkedListMultimap values should be of type Deque<V> HOT 3
- add transformEntries method to Maps and SortedMaps HOT 4
- Be consistent with [Collection]s.new*[Collection](...) HOT 3
- CusomConcurrentHashMap.Values should override toArray(T[]) HOT 2
- with/withoutmethods on immutable collections HOT 2
- OutOfMemoryError when using MapMaker and Soft/Weak-Keys/Values HOT 1
- MemoryLeak(?) when using expiration in MapMaker HOT 2
- equals is not implemented for Collections2.filter HOT 1
- Allow asMap() to return a Map which has defined value Collections HOT 1
- GWT Module missing HOT 3
- Create an alternative to commons-collections MultiKey
- Patch for /trunk/testfw/com/google/common/collect/testing/MapInterfaceTest.java
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-collections.