Table of contents
TOC
Collapse the table of content
Expand the table of content

Set.filter<'T> Function (F#)

Den Delimarsky|Last Updated: 7/25/2016
|
1 Contributor

Returns a new collection containing only the elements of the collection for which the given predicate returns true.

Namespace/Module Path: Microsoft.FSharp.Collections.Set

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

Syntax

// Signature:
Set.filter : ('T -> bool) -> Set<'T> -> Set<'T> (requires comparison)

// Usage:
Set.filter predicate set

Parameters

predicate Type: 'T ->bool

The function to test set elements.

set Type: Set<'T>

The input set.

Return Value

The set containing only the elements for which predicate returns true.

Remarks

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.

Example


    let set1 = Set.ofList [ 1 .. 10]
               |> Set.filter (fun elem -> elem % 2 = 0)
    printfn "%A" set1

Output

set [2; 4; 6; 8; 10]

Platforms

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

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Collections.Set Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2016 Microsoft