c# to f# - Does F# handle inheritance differently compared to C# when type parameters are covariant? -
After the equivalent in C #, I hit something new to me with the following part of the code. The compiler does not meet many errors originally with source.Publish ()
IObservable , despite errors (this is written in the MSDN article according).
Is there anything in F that is different about C #, in this case related to heritage or does anyone tell a provider what is happening? Have I just made a typo which I can not see? What comes to the top in relation to empathy, it is just a wild guess because I am at least temporarily with thoughts and therefore, writing elsewhere can help me and others ...
An example of many error messages:
There is no overload match for 'Create' method Available Overloads are displayed below (or error list window).
There is no overload for the 'Switch' method Available overloads are shown below (or error list window).
error potential overload: '(extension) IObservable.Switch & lt;' TSource> (): IObservable & lt; Type 'TSource>' type constraint mismatch. Type IObservable & LT; IConnectableObservable & lt; '; IObservable & lt; P >> Type IObservable & lt is not compatible with 'a >> type' IObservable & lt; ' One> Make IConnectableObservable & lt 'does not match the type' ;. Open system.Reactive.Concurrency open the System.Reactive.Disposables open System.Reactive.Subjects stable member inline Suspendable (open source system.Reactive.Linq with source) Type pre: IObservable & lt; _ & gt; Suspended: IObservable & lt; bool & gt; isSuspendedInitially: bool): IObservable & lt; _ & Gt; = Observable.Create & LT; _ & Gt; (Fun Supervisor -> Go Shared = source.Publish () go pausable = suspend.StartWith (isSuspendedInitially) .TakeUntil (shared.LastOrDefaultAsync ()) .DistinctUntilChanged () .Select (Fun P -> P Remarkable. Empty & lt; _ & gt; ()) .Switch () New Composite Disposable (Shared), Connect. ()))
Related C # code
public static class RxExtensions {public static IObservable & lt; T & gt; Suspendable & LT; T & gt; (This IObservable & lt; t & gt; section, IObservable & lt; bool & gt; suspends; bool isSuspendedInitially) {Return Observable.Create & LT; T & gt; (O = & gt; {var shared = stream.Publish (); on pausable = .StartWith suspended (isSuspendedInitially) .TakeUntil (shared.LastOrDefaultAsync ()) .DistinctUntilChanged () .Select (? P = & gt; P Shared: Observable.Empty & lt; t & gt; ()) .Switch returned; New CompositeDisposable (pausable.Subscribe (O), shared. Connect ());}); }}
It was a bit tricky, but you need to upload two: < Code> Shared to IObservable & lt; _ & Gt; The result of lambda function on
, and IDisposable
. It will be built in C #, but F #:
Fixed Member Inline Suspendable (Source: IObservable & lt; _ & gt; Suspended: IObservable & Lt; bool & gt; Asuspending start: bool): IObservable & lt; 'A & gt; = Observable.Create & LT; _ & Gt; (Fun Supervisor -> Go Shared = source.Publish () go pausable = suspend.StartWith (isSuspendedInitially) .TakeUntil (shared.LastOrDefaultAsync ()) .DistinctUntilChanged () .Select (Fun P -> P Done: & gt; iossevable & lt; _ & gt; and can be observed empty.Ly; _ & gt; ()) .Switch () New Composite Disposable (Viable. Subscribe (Supervisor), Share. Connect ():: & gt; IDisposable)
Comments
Post a Comment