This topic has not yet been rated - Rate this topic

Event.filter<'T,'Del> Function (F#)

Returns a new event that listens to the original event and triggers the resulting event only when the argument to the event passes the given function.

Namespace/Module Path: Microsoft.FSharp.Control.Event

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
Event.filter : ('T -> bool) -> IEvent<'Del,'T> -> IEvent<'T> (requires delegate)

// Usage:
Event.filter predicate sourceEvent
predicate

Type: 'T -> bool

The function to determine which triggers from the event to propagate.

sourceEvent

Type: IEvent<'Del,'T>

The input event.

An event that only passes values that pass the predicate.

This function is named Filter in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.

The following code example shows how to use the Event.filter function. In this example, mouse events are passed on only when the mouse pointer is in a certain region.

let form = new Form(Text = "F# Windows Form",
                    Visible = true,
                    TopMost = true)
form.MouseMove
    |> Event.filter ( fun evArgs -> evArgs.X > 100 && evArgs.Y > 100)
    |> Event.add ( fun evArgs ->
        form.BackColor <- System.Drawing.Color.FromArgb(
            evArgs.X, evArgs.Y, evArgs.X ^^^ evArgs.Y) )

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.