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

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)

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

// Usage:
Set.filter predicate set


  • 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.


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 illustrates the use of the Set.filter function.

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


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


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#)