Event.choose<'T,'U,'Del> Function (F#)
Returns a new event which fires on a selection of messages from the original event. The selection function takes an original message to an optional new message.
Namespace/Module Path: Microsoft.FSharp.Control.Event
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature:
Event.choose : ('T -> 'U option) -> IEvent<'Del,'T> -> IEvent<'U> (requires delegate)
// Usage:
Event.choose chooser sourceEvent
Parameters
chooser
Type: 'T -> 'U optionThe function to select and transform event values to pass on.
sourceEvent
Type: IEvent<'Del,'T>The input event.
Return Value
An event that fires only when the chooser returns Some.
Remarks
This function is named Choose in compiled assemblies. If you are accessing the function from a .NET language other than F#, or through reflection, use this name.
Example
The following code example shows how to use the Event.choose function. In this example, the function is used to select only events when the mouse button is down. At the same time, the function transforms the input data of type MouseEventArgs into a more convenient format, a tuple of two integers that represent the current mouse position.
// When the mouse button is down, the form changes color
// as the mouse pointer is moved.
let form = new Form(Text = "F# Windows Form",
Visible = true,
TopMost = true)
form.MouseMove
|> Event.choose(fun evArgs ->
if (evArgs.Button <> MouseButtons.None) then
Some( evArgs.X, evArgs.Y)
else None)
|> Event.add ( fun (x, y) ->
form.BackColor <- System.Drawing.Color.FromArgb(
x, y, x ^^^ y) )
Platforms
Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2
Version Information
F# Runtime
Supported in: 2.0, 4.0
Silverlight
Supported in: 3
See Also
Reference
Microsoft.FSharp.Control Namespace (F#)
Change History
Date |
History |
Reason |
---|---|---|
September 2010 |
Added code example. |
Information enhancement. |