Joe Pinder
Joe Pinder

Reputation: 41

How to use CombineLatest in Rx.NET for 2 different types

I cant work out what the syntax is to combine these two observables, property Configuration and BalanceDtos in Rx.NET, can do it in RxJS no problem (example below), any ideas? This is as close as I can get it, but its not correct.

public IObservable<Subroutine> Configuration { get; set; }

    public List<IObservable<List<OtherObject>>> BalanceDtos { get; set; }

    public IObservable<List<OtherObject>> GetSubRoutinesTotal
    {
        get
        {
            return Observable.CombineLatest(Configuration, BalanceDtos.CombineLatest()).Select((config, bals) =>
            {
                Subroutine test1 = config; //these are the objects that I want coming out of this CombineLatest observable.
                List<OtherObject> test2 = bals;
            });
        }
    }

So what I want is when either the property Configuration observable changes, or any of the observables in the BalanceDto property change it should emit that change

Marbles would be:

-c1-b1-b2-b3-c2
---[c1,b1]-[c1,b2]-[c1-b3]-[c2,b3] 

With RxJS in typescript I would write the following:

let obsArray$: Observable<Subroutine>;
   let otherModel$: Observable<OtherObject>[];
   combineLatest([obsArray$, combineLatest(otherModel$)]).subscribe(([obsArray, otherModel]) => {
       let test1: Subroutine = obsArray;
       let tes2: OtherObject[] = otherModel;
   });

I just cant work out what the syntax is for the same thing in Rx.NET. I have looked at other examples for Rx.NET CombineLatest, but they always combine objects of the same type.

Upvotes: 1

Views: 1597

Answers (1)

Joe Pinder
Joe Pinder

Reputation: 41

I have figured out how to do this now, here is the solution:

public IObservable<Subroutine> Configuration { get; set; }

    public List<IObservable<List<OtherObject>>> BalanceDtos { get; set; }

    public IObservable<List<OtherObject>> GetSubRoutinesTotal
    {
        get
        {
           return BalanceDtos.CombineLatest().CombineLatest(Configuration, (bals, config) =>
            {
                Subroutine test1 = config; //these are the objects that I want coming out of this CombineLatest observable.
                IList<List<OtherObject>> test2 = bals;
                return test2[0];
            });
        }
    }

Upvotes: 1

Related Questions