-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
A write-through Converter.convertAll(List) #985
Comments
Original comment posted by wasserman.louis on 2012-05-01 at 05:19 PM This is more or less the same as issue 970 and issue 219. |
Original comment posted by pfnguyen on 2012-05-01 at 05:25 PM So the basic answer is to wait for Converter to be open-sourced, what's an ETA on this? If it's relatively soonish, I'd rather not go and implement this myself. |
Original comment posted by wasserman.louis on 2012-05-01 at 05:29 PM The last I heard, it was a pretty long ways off. Do you have an actual specific use case? We might be able to suggest a better solution. Labels: |
Original comment posted by pfnguyen on 2012-05-01 at 05:33 PM I have a list of backing data that is transformed for presentation and front-end use. The front end wants to be able to persist changes to the backend, but only using the front-end model objects. I would like allow the user of my api to insert, reorder and append model objects that are automatically converted into the backing data format. I don't want to have a parallel add api nor risk the user of my returned list hitting an UnsupportedOperationException by doing something that's not documented to work. |
Original comment posted by [email protected] on 2012-05-01 at 10:06 PM Issue 177 covers releasing Converter, including methods convertAll(Iterable) and convertAll(Iterator). It also mentions that adding convertAll(Collection) and/or convertAll(List) would be mildly convenient, but didn't point out the possibility that the latter could be write-through. The tragic part is that, with Converter in common.base, those methods would not be able to make use of anything in common.collect. But we could still shift gears and go with Lists.transform(List, Converter)... I have reservations about whether this is really all still within the bounds of normal Collection behavior, or if this is crossing that ill-defined line beyond which lies unpredictable, surprising code. In general, the more I've worked with collections, the more I have come to want a collection to be "just a collection", not trying to do fancy things behind the scenes. I'll just leave it at that for now. Status: |
Original comment posted by pfnguyen on 2012-05-02 at 04:36 AM I understand what you mean, I ran into some surprising behavior if some of the conversions aren't memoized. (Although this was in the normal case and not reverse). |
Original comment posted by wasserman.louis on 2012-05-03 at 04:17 PM (No comment entered for this change.) Blocked On: #177 |
Original comment posted by [email protected] on 2012-05-10 at 06:42 PM (No comment entered for this change.) Owner: [email protected] |
Original comment posted by [email protected] on 2012-05-10 at 11:15 PM First, I don't think we should even consider this unless we introduce a more specific InvertibleConverter type. A List to which "add(e); contains(e)" returns false is too damn weird a List for me. But second, even then, I continue to feel that this crosses a certain line. So far our transforming views have just been views; this takes it to a new level. For now, I'm closing, but feel free to add more justification. Status: |
Original issue created by pfnguyen on 2012-05-01 at 05:07 PM
From javadoc for Lists.transform:
"Since functions are not reversible, the transform is one-way and new items cannot be stored in the returned list. The add, addAll and set methods are unsupported in the returned list."
Removal operations are still supported.
I would very much like to have a seamless insertion functionality as well; this could be easily implemented by adding an optional third argument to transform, "reverseTransform"
e.g.
public <A,B> List<B> Lists.transform(List<A>, Function<A,B> forward, Function<B,A> reverse);
where reverse is nullable and an overload exists for the original 2 parameter form.
Of course, all the insertions methods in the resultant collections would need to be overridden to perform the reverse transform as necessary.
The text was updated successfully, but these errors were encountered: