How to join multiple IObservable sequences?

后端 未结 4 1495
無奈伤痛
無奈伤痛 2021-01-02 12:26
        var a = Observable.Range(0, 10);
        var b = Observable.Range(5, 10);
        var zip = a.Zip(b, (x, y) => x + \"-\" + y);
        zip.Subscribe(Conso         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-02 12:37

    How about using the new Join operator in v.2838.

    var a = Observable.Range(1, 10);
    var b = Observable.Range(5, 10);
    
    var joinedStream = a.Join(b, _ => Observable.Never(), _ => Observable.Never(), 
        (aOutput, bOutput) => new Tuple(aOutput,  bOutput))
        .Where(tupple => tupple.Item1 == tupple.Item2);
    
    joinedStream.Subscribe(output => Trace.WriteLine(output));
    

    This is my first look at Join and I'm not sure if it'd be wise to use the Never operator like this. When dealing with a large volumes of inputs as it'd gernerate a huge amount opertaions the more inputs were revieved. I would think that work could be done to close the windows as matche are made and make the solution more efficient. That said the example above works as per your question.

    For the record I think Scott's answer is probably the way to go in this instance. I'm just throwing this in as a potential alternative.

提交回复
热议问题