Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6578565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:47:12+00:00 2026-05-25T15:47:12+00:00

I was working on an app using Reactive Extensions and got into the following

  • 0

I was working on an app using Reactive Extensions and got into the following problem:

say i have two observers P and Q, i want to build a third observer R that if two values of P comes without a Q, R outputs 0. And if after a P comes a Q, R outputs the result of a method passing those values, something like:

P0    Q0    ->    R0 = f(P0,Q0)    
P1          ->    R1 = 0    
P2    Q1    ->    R2 = f(P2,Q1)    
P3          ->    R3 = 0    
P4          ->    R4 = 0    
P5    Q2    ->    R5 = f(P5,Q2)
(...)

and the values come into the obsevers in the following order:

P0 Q0 P1 P2 Q1 P3 P4 P5 Q2

thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:47:13+00:00Added an answer on May 25, 2026 at 3:47 pm

    Suppose we have two methods

    1. Before, Merges two observable sequences into one observable sequence by using a selector function whenever the first observable produces an element rigth before the second one.
    2. Without, Merges an observable sequence into other observable sequence every time two items came togheter from the first observable without any item from the second one.

    With this methods the problem is almost solved.

    IObservable<TP> P = // observer P
    IObservable<TQ> Q = // observer Q
    
    var PP = P.Without((prev, next) => 0, Q);
    var PQ = P.Before(Q, (p,q) => f(p,q)); // apply the function
    
    var ResultSecuence = PP.Merge(PQ);
    

    And here are the two methods

    public static class Observer
    {
        /// <summary>
        /// Merges two observable sequences into one observable sequence by using the selector function 
        /// whenever the first observable produces an element rigth before the second one.
        /// </summary>
        /// <param name="first"> First observable source.</param>
        /// <param name="second">Second observable source.</param>
        /// <param name="resultSelector">Function to invoke whenever the first observable produces an element rigth before the second one.</param>
        /// <returns>
        /// An observable sequence containing the result of combining elements of both sources 
        /// using the specified result selector function.
        /// </returns>
        public static IObservable<TResult> Before<TLeft, TRight, TResult>(this IObservable<TLeft> first, IObservable<TRight> second, Func<TLeft, TRight, TResult> resultSelector)
        {
            var result = new Subject<TResult>();
    
            bool firstCame = false;
            TLeft lastLeft = default(TLeft);
    
            first.Subscribe(item =>
            {
                firstCame = true;
                lastLeft = item;
            });
    
            second.Subscribe(item =>
            {
                if (firstCame)
                    result.OnNext(resultSelector(lastLeft, item));
    
                firstCame = false;
            });
    
            return result;
        }
    
        /// <summary>
        /// Merges an observable sequence into one observable sequence by using the selector function 
        /// every time two items came from <paramref name="first"/> without any item of any observable
        /// in <paramref name="second"/>
        /// </summary>
        /// <param name="first"> Observable source to merge.</param>
        /// <param name="second"> Observable list to ignore.</param>
        /// <param name="resultSelector">Function to invoke whenever the first observable produces two elements without any of the observables in the secuence produces any element</param>
        /// <returns>
        /// An observable sequence containing the result of combining elements
        /// using the specified result selector function.
        /// </returns>
        public static IObservable<TResult> Without<TLeft, TResult>(this IObservable<TLeft> first,  Func<TLeft, TLeft, TResult> resultSelector,params IObservable<object>[] second)
        {
            var result = new Subject<TResult>();
    
            bool firstCame = false;
            TLeft lastLeft = default(TLeft);
    
            first.Subscribe(item =>
            {
                if (firstCame)
                    result.OnNext(resultSelector(lastLeft, item));
    
                firstCame = true;
                lastLeft = item;
            });
    
            foreach (var observable in second)
                observable.Subscribe(item => firstCame = false);
    
            return result;
        }        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a web app using C# and asp.net I have been
I am working on an iPhone Web App using HTML & CSS. I have
I am working on an iPhone app using a SQLite db. I have some
I am working with a java Twitter app (using Twitter4J api). I have created
Im working on an ios app using objective c and i have an issue
I'm currently working on an app using MVVM that needs to have some data
working on an app and using the following code: - (void)viewDidLoad { [super viewDidLoad];
I have been working on a small web app using the Stripes framework. Now
I'm working with Aptana 3 to build a PHP-based web app using phpfog. I
I'm working on an iOS5 app using storyboard, and I have a method in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.