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

Compose/Transformer #1416

Closed
benjchristensen opened this issue Jul 8, 2014 · 7 comments
Closed

Compose/Transformer #1416

benjchristensen opened this issue Jul 8, 2014 · 7 comments
Assignees
Milestone

Comments

@benjchristensen
Copy link
Member

Should we add a chain method, similar to lift but that takes a function from Observable<T> to Observable<R>?

This carries on the conversation from #983. A summary can be found at #983 (comment).


Signature:

public <R> Observable<R> chain(Func1<? super Observable<T>,? extends Observable<R>> function)

Usage:

//puts 0 before and 100 after an observable
Func1<Observable<Integer>,Observable<Integer>> surround = (Observable<Integer> source) -> {
     return Observable.concat(Observable.just(0), source,Observable.just(100));
};

List<Integer> list = Observable.range(1, 3)
     // surround the source with 0 and 100
     .chain(surround)
     //get as a list
     .toList().toBlockingObservable().single();

This would emit 0,1,2,3,100.

Similar to lift, do we need a cover type on this as well to handle generics? Right now the T and R are not marked super and I think they need to be.

@headinthebox
Copy link
Contributor

How is that different from .publish that's already there?

@benjchristensen
Copy link
Member Author

This would not use multicast under the covers and would therefore be more efficient and retain subscription chains as it would not create a "hot observable" as publish does.

@headinthebox
Copy link
Contributor

Yes, that's what I imagined. Could we call it lift as well, or does that lead to erasure troubles?

@benjchristensen
Copy link
Member Author

I'd have to play with Groovy and Clojure to see. We'd likely want another type like Operator that is a cover for generics insanity. Not sure what to call this one.

@benjchristensen
Copy link
Member Author

Discussing with @headinthebox the more appropriate name for this is compose.

public <R> Observable<R> compose(Func1<? super Observable<T>,? extends Observable<R>> function)

With the cover type:

public <R> Observable<R> compose(Transformer<T, R> function)

public interface Transformer<T, R> extends Func1<? super Observable<? super T>,? extends Observable<? extends R>>;

NOTE: Not sure about the co/contra-variance in that signature.

@benjchristensen benjchristensen changed the title Chain method Compose/Transformer Aug 8, 2014
@benjchristensen benjchristensen added this to the 0.20 milestone Aug 8, 2014
@benjchristensen benjchristensen self-assigned this Aug 8, 2014
benjchristensen added a commit to benjchristensen/RxJava that referenced this issue Aug 12, 2014
See ReactiveX#1416 for discussion that led to this.

This does not have co/contra-variance which needs to be figured out.
benjchristensen added a commit to benjchristensen/RxJava that referenced this issue Aug 12, 2014
Failing test while exploring generic variance for ReactiveX#1416
This was referenced Aug 12, 2014
@benjchristensen
Copy link
Member Author

I added compose in #1568 but wasn't able to figure out the co/contra-variance so I've got #1569 open. Can someone help me out with that black art?

If super/extends doesn't work for it, then maybe we should change compose(Transformer<T, R> transformer) to compose(Func1<Observable<T>, Observable<R>>) since the Transformer type is not probably not needed if we're not hiding generics complexity.

/cc @headinthebox

abersnaze pushed a commit to abersnaze/RxJava that referenced this issue Aug 13, 2014
Failing test while exploring generic variance for ReactiveX#1416
@benjchristensen
Copy link
Member Author

Thanks @abersnaze for the fix to variance. Closing this.

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

2 participants