是否可以通过单击按钮打印当前观察的结果?
示例:
button.Click.Add(fun _ -> x |>Observable.subscribe (fun x -> printfn "%A" x))
您可以将订阅获得的最后一个值存储在ref
:中
let curX = ref None
let subscription = x |> Observable.subscribe (fun v ->
lock curX (fun () -> curX := Some v)
)
button.Click.Add (fun _ ->
match lock curX (fun () -> !curX) with
| Some v -> printfn "X yielded "%A"." v
| None -> printfn "X yielded nothing."
)