square/retrofit — pull request #346 by adriancole (2013-11-07 21:45:21+00:00)
Title: Start RxJava integration

Currently, creating an RxJava Observer from a Retrofit implementation is hard coding something like this:

```java

interface GitHub {

@GET("/repos/{owner}/{repo}/contributors")
List contributors(@Path("owner") String owner, @Path("repo") String repo);
}

// write an interface that invokes contributors on subscribe
class Contributors implements OnSubscribeFunc> {
private final GitHub api;
private final String owner;
private final String repo;

public Contributors(GitHub api, String owner, String repo) {
this.api = api;
this.owner = owner;
this.repo = repo;
}

@Override public Subscription onSubscribe(Observer> observer) {
observer.onNext(api.contributors(owner, repo));
observer.onCompleted();
return Subscriptions.empty();
}
}

--snip--
// create a retrofit adapter normally
api = restAdapter.create(GitHub.class);

// create an observable which invokes the http call on subscribe
Observable> retrofitContributors = Observable.create(new Contributors(api, "square", "retrofit"));
```

This works, but it involves a lot of boilerplate coding to create the OnSubscribe function. An alternate would be to allow Retrofit interfaces to extend RxJava function and coerce the function and its params to an `OnSubscribeFunc`.

Ex.
```java

// implement a function that can be coerced to an RxJava OnSubscribeFunc
interface Contributors extends Func2> {

@Override @GET("/repos/{owner}/{repo}/contributors")
List call(@Path("owner") String owner, @Path("repo") String repo);
}

--snip--
// create a retrofit adapter normally
api = restAdapter.create(Contributors.class);

// create an observable which invokes the http call on subscribe
Observable> retrofitContributors = Observable.create(toOnSubscribeFunc(api, "square", "retrofit"));
```

### Changes
* The first commit in this pull request allows retrofit interfaces to extend functional (single-method) interfaces.
* The second is optional, for now, as it has no retrofit code in it :) It just shows how to do the above via.

cc @benjchristensen