nikgoodley-ibboost / funcito

Automatically exported from code.google.com/p/funcito
0 stars 0 forks source link

Add conversion from a "framework" to another (from exemple: Guava to RxJava) ? #76

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
> What steps will reproduce the problem?
It's an enhancement.

> What is the expected output? What do you see instead?

If on a project I use Guava & RxJava. I have to define something like that :

----------------------------------
// For Guava.
public final static Personne Personne_G = FuncitoGuava.callsTo(Personne.class);
public final static Function<Personne, Integer> getAge_g = 
FuncitoGuava.functionFor(Personne_G.getAge());
...

// For RxJava.
public final static Personne Personne_R = FuncitoRxJava.callsTo(Personne.class);
public final static Func1<Personne, Integer> getAge_r = 
FuncitoRxJava.func1For(Personne_R.getAge());
...
-----------------------------------

It could be great to have something like "conversion" method(s) :

// RxJava Func1 "computed" from the Guava Function.
public final static Func1<Personne, Integer> getAge_r = 
FuncitoRxJava.from(getAge_g);

Regards,
Ronan.

Original issue reported on code.google.com by ronan.mi...@gmail.com on 31 Oct 2013 at 10:21

GoogleCodeExporter commented 9 years ago
I infer that you are mainly wanting to add the brevity of not having to 
redefine a Personne proxy for both frameworks.

But proxies can be reused both within AND between supported APIs, so how about 
just using the following instead of defining conversions:
---------------------
import org.funcito.Funcito;
import org.funcito.FuncitoGuava;
import org.funcito.FuncitoRxJava;
public final static Personne PERSONNE = Funcito.callsTo(Personne.class);
public final static Function<Personne, Integer> getAge_g = 
FuncitoGuava.functionFor(PERSONNE.getAge());
public final static Func1<Personne, Integer> getAge_r = 
FuncitoRxJava.func1For(PERSONNE.getAge());
---------------------

And really, the Funcito.callsTo() and the FuncitoGuava.callsTo() (etc.) are all 
just shortcuts to the same thing.  So you could eliminate importing Funcito if 
you wanted to.  Or in mixed API format, you could *just* import Funcito and do 
the following:
---------------------
import static org.funcito.Funcito.*;
public final static Personne PERSONNE = callsTo(Personne.class);
public final static Function<Personne, Integer> getAge_g = 
guava().functionFor(PERSONNE.getAge());
public final static Func1<Personne, Integer> getAge_r = 
rxJava().func1For(PERSONNE.getAge());
---------------------

Otherwise, I'm not seeing the advantage of conversion methods.  Is there any 
advantage that I am missing?

Original comment by kandpwel...@gmail.com on 1 Nov 2013 at 8:38

GoogleCodeExporter commented 9 years ago
Sharing the same Proxy (ie PERSONNE) between several use is very good.

The advantage of conversion, is just to **be sure to stay synchronised** 
between multiple framework use.

Exemple :

Qux getQux_g = 
guava().functionFor(PERSONNE.getFoo().getTheGoodBar().getBaz().getQux());
...
Qux getQux_r = 
rxJava().functionFor(PERSONNE.getFoo().getOldBar().getBaz().getQux();

Here imagine the developper changed the guava version but forgot to change the 
rxJava version.

Original comment by ronan.mi...@gmail.com on 2 Nov 2013 at 6:39

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
(deleted my comment from a moment ago and reposting with spelling correction):

OK, I understand the theoretical usefulness now.  But is this something you 
would immediately find useful on a regular basis, and do you think many others 
would?  I am very happy to consider adding this, but I always need to make sure 
that any new feature does not amount to "clutter" that would get very little 
use in the community of users.

Some technical notes: all of the factory methods actually return subclasses of 
the 3rd party classes.  For example instead of making a "pure" RxJava class 
Func1, it actually returns a Funcito subclass called RxJavaFunc1.  This is true 
for all supported 3rd party functor classes.  This would theoretically make it 
easy to do what you ask.  Except all of my factory method signatures still 
refer to only the "pure" 3rd party functor classes.  So the user would be 
required to perform a cast to be able to provide the functionality you request. 
 Not terrible, but less beautiful than what I would hope for public API.

Original comment by kandpwel...@gmail.com on 3 Nov 2013 at 2:05

GoogleCodeExporter commented 9 years ago
(continuing from previous post)
So actual usage - per you example -- would probably look more like this (fully 
qualified generics required in the typecast below):

public final static Func1<Personne, Integer> getAge_r = 
FuncitoRxJava.func1From((GuavaFunction<Personne,Integer>)getAge_g);

... a little ugly IMHO, but it is do-able and would accomplish what you want: 
synchronized functors across multiple 3rd party APIs.

Original comment by kandpwel...@gmail.com on 3 Nov 2013 at 2:21