简体   繁体   English

RX获得IObservable <List<T> &gt;到IObservable <T>

[英]RX getting a IObservable<List<T>> to an IObservable<T>

I'm pretty new to RX and cannot figure this out. 我是RX的新手,无法解决这个问题。

I have an IObservable<List<T>> where List<T> is guaranteed to have one element. 我有一个IObservable<List<T>> ,其中List<T>保证有一个元素。

How do I convert this to an IObservable<T> . 如何将其转换为IObservable<T>

I thought it would have something to do with Single but that is listed as obsolete, and also doesn't return an IObservable<T> anyway (as pretty sure it would return the Single List<T> element. 我认为它与Single但是它被列为过时的,并且也不会返回IObservable<T> (因为很确定它会返回Single List<T>元素。

Is there some SelectMany magic I can do here? 我可以在这里做一些SelectMany魔术吗?

You can just do this: 你可以这样做:

IObservable<List<T>> source;

var converted = source.Select(x => x[0]);

Or if you prefer LINQ query comprehension syntax then equivalent is: 或者,如果您更喜欢LINQ查询理解语法,那么等效的是:

var converted = from x in source select x[0];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM