yf0994 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Would there be any value in adding .translate(...) methods? #1117

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The static utility methods in Lists, Sets, etc... contain a transform(...) 
method.  Would there be potential value in creating translate(...) methods 
which would basically do a transform but not maintain a live reference to the 
collection being transformed?

What about supporting multiple return types so that, e.g., one could translate 
a List to a Set?

Original issue reported on code.google.com by adam.n.g...@gmail.com on 23 Aug 2012 at 5:06

GoogleCodeExporter commented 9 years ago
What's wrong with just passing the result of the transform() to 
Lists.newArrayList or Sets.newHashSet?  I think

   Sets.newHashSet(Collections2.transform(set, function))

has a much clearer intent than e.g.

   Sets.translate(set, function) // looking at this, I have no idea what it returns

Original comment by wasserman.louis on 23 Aug 2012 at 5:35

GoogleCodeExporter commented 9 years ago
Yea, that's fair.

Original comment by adam.n.g...@gmail.com on 23 Aug 2012 at 9:21

GoogleCodeExporter commented 9 years ago
Possibly we'll one day change transform() and friends to declare a return type 
of FluentIterable.  If so, this will become "Iterables.transform(...).toSet()."

http://code.google.com/p/guava-libraries/wiki/BridgeMethodInjectorOpportunities

Original comment by cpov...@google.com on 23 Aug 2012 at 9:52

GoogleCodeExporter commented 9 years ago
That would be very cool.  Would that then still be a "live" reference to the 
original collection?

Original comment by adam.n.g...@gmail.com on 23 Aug 2012 at 10:53

GoogleCodeExporter commented 9 years ago
The method would return ImmutableSet so that it can sever the reference.

Original comment by cpov...@google.com on 23 Aug 2012 at 10:56

GoogleCodeExporter commented 9 years ago
Can we mark this as WorkingAsIntended, in any case?

Original comment by wasserman.louis on 23 Aug 2012 at 10:59

GoogleCodeExporter commented 9 years ago
@louis.  sounds good to me.  thanks guys for the quick replies.

Original comment by adam.n.g...@gmail.com on 23 Aug 2012 at 11:06

GoogleCodeExporter commented 9 years ago
And of course even without Iterables.transform returning FluentIterable, you 
can always do "FluentIterable.from(...).transform(...).toSet()". And there's 
also ".copyTo(whateverCollection)" for mutable. So yeah, I think we have this 
covered.

Original comment by cgdec...@gmail.com on 23 Aug 2012 at 11:09

GoogleCodeExporter commented 9 years ago

Original comment by cpov...@google.com on 7 Nov 2012 at 7:41

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:13

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08