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

API Design Review: Conditionals #683

Closed
benjchristensen opened this issue Dec 24, 2013 · 11 comments
Closed

API Design Review: Conditionals #683

benjchristensen opened this issue Dec 24, 2013 · 11 comments

Comments

@benjchristensen
Copy link
Member

Discussion with @headinthebox suggests that the conditional operators really don't belong in RxJava (at least not the core) as they were added to Rx.Net for very specific use cases in F#.

These include ifThen, switchCase, doWhile, whileDo.

Are there reasons to keep these? If so do we move them out of Observable or should we delete them?

/cc @headinthebox and @jhusain

@headinthebox
Copy link
Contributor

http://msdn.microsoft.com/en-us/library/dd233182.aspx

I don't know of anyone using this for real in Rx.NET.

@akarnokd
Copy link
Member

These could be moved into a rxjava-contrib/rxjava-dotnet-legacy package along with those ops that have been added just to match Rx.Net.

@sirinath
Copy link

These can be used for CEP scenarios to reason over multiple streams. It is best that they stay in some form or other as Java does not have anonymous classes like C# where they could be easily avoided by joining fields into a anonymous class. They are more needed in the JVM implementation than in .net.

Ideally the senarios should be expanded in RxJava.

@headinthebox
Copy link
Contributor

@sirinath can you give a concrete example? I don't see the connection between these operators which are intended to overload imperative control structures in F# computation expressions and anonymous types.

@sirinath
Copy link

If this is extended to accept an observable sequence as the condition / selector then it would be more useful.

Say I want to buy using signal A if vol is greater than a certain threshold plus some other computationally expensive conditions and signal B otherwise only if I am trading that instrument for the day and I only trade 0.5% of instruments.

The current form is somewhat useful if we want to certain set of signals at start of the day but this is something you can do otherwise eagerly at a cost. Also it would be useful if the conditional is also an observable sequence as you can select between streams than at subscription. Using Linq you can aggregate multiple items into anonymous class and select what is needed at the end from this in a further query. This is more difficult though possible in Java than C# hence it will be good to have the conditional functionality extended for other use cases.

More powerful it would be if you have linq Expressions. This is also possible through Commons JCI or directly using Janino. Perhaps at a later stage.

@sirinath
Copy link

Also the conditions or index can be extended to a function to take 1 item from each stream and return the appropriate values (boolean / index) for item selection. If not subscribers the condition is not evaluated and if possible each item can be discarded from the streams.

This would be a more convinient way to use this functionality.

@headinthebox
Copy link
Contributor

@sirinath Could you provide a concrete example? I am not sure that I understand what you are after precisely.

benjchristensen added a commit to benjchristensen/RxJava that referenced this issue Jan 2, 2014
The conditional operators are going in this contrib module.

See ReactiveX#683
@benjchristensen
Copy link
Member Author

Migrating conditionals to a contrib module: #714

@benjchristensen
Copy link
Member Author

@sirinath
Copy link

sirinath commented Jan 3, 2014

@headinthebox

Add an extra overload with Func<bool, TResult, TResult> condition for if and Func<TValue, TResult[]> selector ... etc.

if(
(a, b) -> !a.equals(obj1) && b.equals(obj2),
strm1,
strm2)

this case condition is evaluated as needed but for each element coming in

@sirinath
Copy link

sirinath commented Jan 5, 2014

@headinthebox

In a nutshell the extension will help combination and generation. Something you can consider for the main implementation also.

benjchristensen added a commit to ReactiveX/RxJavaComputationExpressions that referenced this issue Aug 29, 2014
The conditional operators are going in this contrib module.

See ReactiveX/RxJava#683
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants