Closed shirok1 closed 2 years ago
The method you're referring to is specifically used to convert an delegate event of type Action. In C#, this would be declared as:
public event Action<TEventArgs> Event;
IEvent
is native to F# already implements IObservable
.
type IEvent<'Delegate,'Args> =
inherit System.IObservable<'Args> inherit IDelegateEvent<'Delegate>
so unlike a .NET event delegate, to convert from an F# event to observable, a static cast is sufficient. i.e,
let toObservable (event: IEvent<'a, 'b>) : IObservable<'b> =
event :> IObservable<_>
I see.
https://github.com/fsprojects/FSharp.Control.Reactive/blob/ef1d7c629a8d522abe2101a2a9b1e63038f2f242/src/FSharp.Control.Reactive/Observable.fs#L744
Writing
Observable.fromEventGeneric event.AddHandler event.RemoveHandler
will prompt that'a -> unit
is not implying delegate, however,System.Reactive.Linq.Observable.FromEvent(event.AddHandler, event.RemoveHandler)
works just fine. I actually write my own helper function:I wonder if this is by design.