简体   繁体   中英

F# workflow builder for Rx

There's a nice F# workflow builder for Rx here:

http://blogs.msdn.com/b/dsyme/archive/2011/05/30/nice-f-syntax-for-rx-reactive-extensions.aspx

I've been trying to make a Using implementation for the workflow but keep banging my head against the wall. Maybe it's too late here.

How would one create this?

type RxBuilder () =

    // ...

    member this.Using (disposable, f) =
        Observable.Using(???)

Thanks in advance.

Firstly, the original code needs to be updated slightly for the latest Rx releases. Namely, For and While should be implemented as:

member this.For (xs : 'a seq, f: 'a -> 'b IObservable) =
    Observable.SelectMany(xs.ToObservable(), new Func<_, IObservable<_>>(f)) 

member this.While (f, xs: 'a IObservable) =
    Observable.TakeWhile (xs, new Func<_,bool>(fun _ -> f()))

Then, based on this , you can use the following for an implementation of Using :

member this.Using(res:#IDisposable, body) = this.TryFinally(body res, fun () -> match res with null -> () | disp -> disp.Dispose())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM