Skip to content

Instantly share code, notes, and snippets.

@smallgeek
Created March 25, 2017 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smallgeek/63f1a211f3187bc2e982ed9229c203c3 to your computer and use it in GitHub Desktop.
Save smallgeek/63f1a211f3187bc2e982ed9229c203c3 to your computer and use it in GitHub Desktop.
リアクティブプログラミングの擬似コードでよく見るやつ
open System
open System.Reactive
open System.Reactive.Subjects
open System.Reactive.Linq
open Microsoft.FSharp.Control
open FSharp.Control.Reactive
open FSharp.Control.Reactive.Builders
open FSharp.Data
type BehaviorSubject<'a> with
member this.setValue x = this.OnNext x
type Cell<'a> = BehaviorSubject<'a>
type ExcelBuilder() =
let mutable transit: IObservable<_> = null
member __.Bind(m: IObservable<_>, f: _ -> IObservable<_>) =
transit <- Observable.bind f m
transit
member __.Return(x) =
let source = Observable.publishInitial x transit
source :?> IObservable<_>
let excel = new ExcelBuilder()
let a1 = new Cell<int> 1
let b1 = new Cell<int> 2
let c1 = excel {
let! x = a1
let! y = b1
return x + y
}
c1 |> Observable.subscribe (fun x -> printfn "%i" x) |> ignore
a1.setValue 3 // a1(3) + b1(2)
stdin.Read() |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment