Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to add concrete implementation of monad for IObservable<'a> ? #459

Open
Hong-Xiang opened this issue Jul 10, 2021 · 1 comment

Comments

@Hong-Xiang
Copy link

Hong-Xiang commented Jul 10, 2021

Currently IObservable<'a> works fine with map / |>>, but does not work with monad CE.

Since IObservable<'a> has LINQ extension methods IObservable.Select, IObservable.SelectMany and Observable.Return. It seems that it might be nature to have monad instance just following System.Reactive.Linq 's implementation.

As discussed in here, adding concrete implementation for IObservable<'a> in FSharpPlu.Control might be the easiest way to achieve this.

Is it possible to add monad instance concrete implementation directly to F#+?

If there is no other constrains, adding concreate implementation in Control/Monad.fs might be as easy as several lines of code to direct call IObservable<'a>'s corresponding extension methods.

But there might be some problems, like introduce dependency to System.Reactive, and maybe Using / Defer and other methods needs also be considered. But considering IObservable<'a> is already provided in System namespace, and Rx.Net is an popular functional style library, solving these problems might have enough benefits.

@gusty
Copy link
Member

gusty commented Jul 10, 2021

But there might be some problems, like introduce dependency to System.Reactive,

I think that's the main concern.

We could add an implementation that doesn't take a dependency on System.Reactive, but I'm not very familiar with the details of different implementations of SelectMany.

In anycase, it should always be possible to "extract" the SelectMany code from System.Reactive (since it's open source) and put it here in an Observable.fs extension file, then add the corresponding overload for >>=.

If you want to go that road that contribution would be more than welcome and I can certainly help you integrating it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants