Compartilhar via


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

Returns a new event that passes values transformed by the given function.

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

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

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

// Usage:
Event.map mapping sourceEvent

Parameters

  • mapping
    Type: 'T -> 'U

    The function to transform event values.

  • sourceEvent
    Type: IEvent<'Del,'T>

    The input event.

Return Value

An event that passes the transformed values.

Remarks

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

Example

The following code example shows how to use the Event.map function. In this example, the event handler arguments are transformed into a more convenient format.

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

Platforms

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

Version Information

F# Core Library VersionsF# Core Library Versions

Supported in: 2.0, 4.0, Portable2.0, 4.0, Portable, Portable

See Also

Reference

Control.Event Module (F#)

Microsoft.FSharp.Control Namespace (F#)