Skip to content

API Design Review: Conditionals #683

Closed

Description

@benjchristensen

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

Activity

  1. headinthebox commented on Dec 24, 2013

    @headinthebox
    Contributor

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

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

  2. akarnokd commented on Dec 24, 2013

    @akarnokd
    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.

  3. sirinath commented on Dec 27, 2013

    @sirinath

    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.

  4. headinthebox commented on Dec 27, 2013

    @headinthebox
    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.

  5. sirinath commented on Dec 28, 2013

    @sirinath

    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.

  6. sirinath commented on Dec 30, 2013

    @sirinath

    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.

  7. headinthebox commented on Jan 2, 2014

    @headinthebox
    Contributor

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

  8. added a commit that references this issue on Jan 2, 2014
  9. benjchristensen commented on Jan 2, 2014

    @benjchristensen
    MemberAuthor

    Migrating conditionals to a contrib module: #714

  10. benjchristensen commented on Jan 2, 2014

    @benjchristensen
    MemberAuthor
  11. sirinath commented on Jan 3, 2014

    @sirinath

    @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

  12. sirinath commented on Jan 5, 2014

    @sirinath

    @headinthebox

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

  13. added a commit that references this issue on Aug 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions