Gu.Reactive icon indicating copy to clipboard operation
Gu.Reactive copied to clipboard

AsReadonlyView extension method

Open JohanLarsson opened this issue 6 years ago • 2 comments

var view = foo.ObserveValue(x => x.Items).AsReadOnlyView();

JohanLarsson avatar May 27 '19 13:05 JohanLarsson

Workaround 1:

var view = foo.ObserveValue(x => x.Items)
              .Select(x => x.GetValueOrDefault())
              .AsReadOnlyView()

Workaround 2:

var view = foo.ObserveValue(x => x.Items)
              .Select(x => (IMaybe<int[]>)x)
              .AsReadOnlyView()

We can add ObserveEnumerableValue() that returns IMaybe<IEnumerable<T>> but not sure it is worth it.

Another alternative is to generate overloads for common collection types but it will not work for immutable collections which is a common use case.

JohanLarsson avatar Sep 07 '19 11:09 JohanLarsson

Not doing anything with this, chances are shapes will solve it in the future.

JohanLarsson avatar Sep 07 '19 11:09 JohanLarsson