3

I've started to play around with the rx version of C# recently and am wondering how it's possible to solve the following problem:

I'm using refit to get a list of items from a server via:

[Get("/items")]
IObservable<List<Item>> GetItems();

I would like to process each item afterwards, but I didn't find out how to do that. I know in RxJava there is an operator called flatMapIterable() which allows me to process each item, but I didn't find something similar for C#.

Thanks

David Pine
  • 23,787
  • 10
  • 79
  • 107
tobi_b
  • 1,218
  • 1
  • 12
  • 21

2 Answers2

4

According to the documentation, you need the .SelectMany.

[Get("/items")]
IObservable<List<Item>> GetItems() 
{
    observable.SelectMany(t => t);
}

In the Rx.NET repo, you can look at the implementation of the source - if you're interested.

David Pine
  • 23,787
  • 10
  • 79
  • 107
2

You need SelectMany();

IObservable<List<Item>> observable = new List<List<Item>>().ToObservable();
var flattened = observable.SelectMany(i => i);
David Pine
  • 23,787
  • 10
  • 79
  • 107
Peter Bons
  • 26,826
  • 4
  • 50
  • 74