Programming F# 3.0 by Chris Smith

Programming F# 3.0 by Chris Smith

Author:Chris Smith [Chris Smith]
Language: eng
Format: epub, pdf
Tags: COMPUTERS / Programming Languages / General
ISBN: 9781449335519
Publisher: O'Reilly Media
Published: 2012-04-04T16:00:00+00:00


However, Observable.filter and Observable.partition are not the only useful methods in the module.

Observable.add

Observable.add simply subscribes to the event. Typically this method is used at the end of a series of pipe-forward operations and is a cleaner way to subscribe to events than calling AddHandler on the event object.

Observable.add has the following signature:

val add : ('a -> unit) -> IObservable<'a> -> unit

Example 8-16 pops up a message box whenever the mouse moves into the bottom half of a form.

Example 8-16. Subscribing to events with Observable.add

open System.Windows.Forms let form = new Form(Text="Keep out of the bottom!", TopMost=true) form.MouseMove |> Observable.filter (fun moveArgs -> moveArgs.Y > form.Height / 2) |> Observable.add (fun moveArgs -> MessageBox.Show("Moved into bottom half!") |> ignore) form.ShowDialog()



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.