Set<'T> Type
Immutable sets based on binary trees, where elements are ordered by F# generic comparison. By default comparison is the F# structural comparison function or uses implementations of the IComparable interface on element values.
See the Set module for further operations on sets. All members of this class are thread-safe and may be used concurrently from multiple threads.
Constructors
Constructor |
Description
|
|
Create a set containing elements drawn from the given sequence.
Example
val sequenceOfNumbers: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq -------------------- type 'T seq = System.Collections.Generic.IEnumerable<'T> val numbersInSet: Set<int>
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val printfn: format: Printf.TextWriterFormat<'T> -> 'T
|
Instance members
Instance member |
Description
|
A useful shortcut for Set.add. Note this operation produces a new set and does not mutate the original set. The new set will share many storage nodes with the original. See the Set module for further operations on sets.
Example
val set: Set<int>
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val empty<'T (requires comparison)> : Set<'T> (requires comparison)
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
The sample evaluates to the following output: The new set is: set [1; 2]
|
|
Full Usage:
this.Contains
Parameters:
'T
-
The value to check.
Returns: bool
True if the set contains value .
|
A useful shortcut for Set.contains. See the Set module for further operations on sets.
Example
val set: Set<int>
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val empty<'T (requires comparison)> : Set<'T> (requires comparison)
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
member Set.Contains: value: 'T -> bool
The sample evaluates to the following output: Does the set contain 1? false
|
|
The number of elements in the set
Example
val set: Set<int>
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val empty<'T (requires comparison)> : Set<'T> (requires comparison)
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
property Set.Count: int with get
The sample evaluates to the following output: The set has 3 elements
|
|
A useful shortcut for Set.isEmpty. See the Set module for further operations on sets.
Example
val set: Set<int>
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val empty<'T (requires comparison)> : Set<'T> (requires comparison)
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
property Set.IsEmpty: bool with get
The sample evaluates to the following output: Is the set empty? false
|
|
Evaluates to "true" if all elements of the first set are in the second, and at least one element of the second is not in the first.
Example
val set1: Set<int>
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val empty<'T (requires comparison)> : Set<'T> (requires comparison)
val set2: Set<int>
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
The sample evaluates to the following output: Is set [1; 2; 3] a proper subset of set [1; 2; 3; 4]? true
|
|
Evaluates to "true" if all elements of the second set are in the first, and at least one element of the first is not in the second.
Example
val set1: Set<int>
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val empty<'T (requires comparison)> : Set<'T> (requires comparison)
val set2: Set<int>
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
The sample evaluates to the following output: Is set [1; 2; 3] a proper superset of set [1; 2; 3; 4]? false
|
|
Evaluates to "true" if all elements of the first set are in the second.
Example
val set1: Set<int>
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val empty<'T (requires comparison)> : Set<'T> (requires comparison)
val set2: Set<int>
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
The sample evaluates to the following output: Is set [1; 2; 3] a subset of set [1; 2; 3; 4]? true
|
|
Evaluates to "true" if all elements of the second set are in the first.
Example
val set1: Set<int>
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val empty<'T (requires comparison)> : Set<'T> (requires comparison)
val set2: Set<int>
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
The sample evaluates to the following output: Is set [1; 2; 3] a superset of set [1; 2; 3; 4]? false
|
Full Usage:
this.MaximumElement
Returns: 'T
|
Returns the highest element in the set according to the ordering being used for the set.
Example
val set: Set<int>
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val empty<'T (requires comparison)> : Set<'T> (requires comparison)
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
property Set.MaximumElement: int with get
The sample evaluates to the following output: MaximumElement: 3
|
Full Usage:
this.MinimumElement
Returns: 'T
|
Returns the lowest element in the set according to the ordering being used for the set.
Example
val set: Set<int>
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val empty<'T (requires comparison)> : Set<'T> (requires comparison)
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
property Set.MinimumElement: int with get
The sample evaluates to the following output: MinimumElement: 1
|
Full Usage:
this.Remove
Parameters:
'T
-
The value to remove from the set.
Returns: Set<'T>
The result set.
|
A useful shortcut for Set.remove. Note this operation produces a new set and does not mutate the original set. The new set will share many storage nodes with the original. See the Set module for further operations on sets.
Example
val set: Set<int>
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val empty<'T (requires comparison)> : Set<'T> (requires comparison)
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
The sample evaluates to the following output: The new set is: set [2]
|
Static members
Static member |
Description
|
|
Compute the union of the two sets.
Example
val set1: Set<int>
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val empty<'T (requires comparison)> : Set<'T> (requires comparison)
val set2: Set<int>
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
The sample evaluates to the following output: The new set is: set [1; 2; 3; 4]
|
|
Returns a new set with the elements of the second set removed from the first.
Example
val set1: Set<int>
Multiple items
module Set from Microsoft.FSharp.Collections -------------------- type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ... -------------------- new: elements: 'T seq -> Set<'T> val empty<'T (requires comparison)> : Set<'T> (requires comparison)
val set2: Set<int>
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
The sample evaluates to the following output: The new set is: set [1]
|