-
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
Introduce an InjectiveFunction interface #457
Comments
Original comment posted by antonmarsden on 2010-11-02 at 03:09 AM This enhancement sort of relates to Issue 177 (the InvertibleFunction or Converter interface) - implementing a BijectiveFunction interface would make behavioural guarantees about the function. |
Original comment posted by antonmarsden on 2010-11-02 at 06:36 AM After further thought, you can get some impressive performance advantages if applying a transformation to a BijectiveFunction - add(), remove(), contains(), etc., can all be written to work as efficiently as the transformed Set (in terms of computational complexity, assuming apply() and applyInverse() are constant time operations). Attached is a trivial implementation of a TransformedSet implementation. |
Original comment posted by [email protected] on 2010-11-05 at 05:55 AM We went down this road quite a while ago, but didn't quite get to the endpoint. One thing that held us up was discovering how shockingly many functions people want to use are almost bijective, and seem bijective, but aren't quite -- so subtle bugs will be lurking in your program. This gave us pause, but I don't think it kills the whole idea necessarily. |
Original comment posted by [email protected] on 2011-04-06 at 03:27 AM (No comment entered for this change.) Status: |
Original issue created by antonmarsden on 2010-10-25 at 10:13 PM
An injective function preserves distinctness, and thus can be used to preserve the Set and Map interfaces when applying transformations. For example, the following functionality becomes feasible:
public static <F, T> Set<T> transform( Set<F> fromSet, InjectiveFunction<? super F, T> injectiveFunction )
The InjectiveFunction would simply extend Function - no extra methods are required, but the programmer using the interface must understand the implications of it.
The text was updated successfully, but these errors were encountered: