fsprojects / FSharp.Control.Reactive

Extensions and wrappers for using Reactive Extensions (Rx) with F#.
http://fsprojects.github.io/FSharp.Control.Reactive
Other
284 stars 58 forks source link

Accept sub interfaces of IObservable<T> #71

Closed Evangelink closed 8 years ago

Evangelink commented 8 years ago

Hi,

I am currently using a sub interface from the IObservable and I need to upcast it everytime I use one of your wrapped method. I was wondering if you would see any reason why not replacing all (x : IObservable<_>) with (x : #IObservable<_>) so it can accept sub interfaces?

If you think it is all good for you I will make a PR.

Cheers, Amaury

dsyme commented 8 years ago

Could you give an example? When an F# function with a known argument type is called flexibility is added to allow an upcast from an argument to the argument type, so in most cases using # is not needed. If there is a collection of IObservables, or if using with a combinatory, then it may be needed.

Evangelink commented 8 years ago

I am currently using an IObservable to give my models to my view models along with a wrapper method and wanted to be able to distinguish between when I receive a new model because of a user action of because I am loading data from my repository. So I have started to create an IPopulatableObservable like this:

type IPopulatableObservable<'T> =
    inherit IObservable<'T>
    abstract IsPopulated : IObservable<bool>

and I was using it (as you said) within a collection, getting from:

IObservable<seq<IPopulatableObservable<Model seq>>>

then doing a mergeSeq

IObservable<IPopulatableObservable<Model seq>>

then a switch where I had to do the cast using a map

IObservable<Model seq>

At first, I though the modification would be quite easy but then I end up realising I need to create another IObserver, BehaviorSubject and some other methods like Observable.Create...

Anyway too much things I am not sure how to do so I gave up for now...Meaning I don't really need it anymore. But if you want me to try to recreate a code example I can do it so you could see if it can be useful for someone else.