Skip to content
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

Closed
gissuebot opened this issue Oct 31, 2014 · 4 comments
Closed

Introduce an InjectiveFunction interface #457

gissuebot opened this issue Oct 31, 2014 · 4 comments

Comments

@gissuebot
Copy link

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.

@gissuebot
Copy link
Author

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.

@gissuebot
Copy link
Author

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.

@gissuebot
Copy link
Author

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.

@gissuebot
Copy link
Author

Original comment posted by [email protected] on 2011-04-06 at 03:27 AM


(No comment entered for this change.)


Status: Duplicate
Merged Into: #177

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant