fsprojects / FSharp.Control.Reactive

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

Fix for Observable.choose #142

Closed mrakgr closed 4 years ago

mrakgr commented 4 years ago

Actually I am going to have to do another PR as I realized something that I've missed.

                public override void OnNext(TSource value)
                {
                    TResult result;
                    try
                    {
                        result = _selector(value);
                    }
                    catch (Exception exception)
                    {
                        ForwardOnError(exception);
                        return;
                    }

                    ForwardOnNext(result);
                }

This is how Select is implemented in C#.

ForwardOnNext(result);

Note how this is on the last line. This will no doubt trigger the tail call, while in my version...

(fun x -> try f x |> Option.iter o.OnNext with ex -> o.OnError ex)

Has the call to o.OnNext inside try. Sorry about that. It did not occur to me while I was working on it. Let me give it a shot again.

panesofglass commented 4 years ago

Merged!