Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

array/list.distinct and fixes to seq.distinct #236

Merged
merged 1 commit into from
Jul 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/conceptual/TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
######[Array.copy<'T> Function](array.copy['t]-function-[fsharp].md)
######[Array.countBy<'T,'Key> Function](array.countby['t,'key]-function-[fsharp].md)
######[Array.create<'T> Function](array.create['t]-function-[fsharp].md)
######[Array.distinct['t] Function](array.distinct['t]-function-[fsharp].md)
######[Array.empty<'T> Type Function](array.empty['t]-type-function-[fsharp].md)
######[Array.exists<'T> Function](array.exists['t]-function-[fsharp].md)
######[Array.exists2<'T1,'T2> Function](array.exists2['t1,'t2]-function-[fsharp].md)
Expand Down Expand Up @@ -305,6 +306,7 @@
######[List.concat<'T> Function](list.concat['t]-function-[fsharp].md)
######[List.contains<'T> Function](list.contains['t]-function-[fsharp].md)
######[List.countBy<'T,'Key> Function](list.countby['t,'key]-function-[fsharp].md)
######[List.distinct['t] Function](list.distinct['t]-function-[fsharp].md)
######[List.empty<'T> Type Function](list.empty['t]-type-function-[fsharp].md)
######[List.exists<'T> Function](list.exists['t]-function-[fsharp].md)
######[List.exists2<'T1,'T2> Function](list.exists2['t1,'t2]-function-[fsharp].md)
Expand Down
71 changes: 71 additions & 0 deletions docs/conceptual/array.distinct['t]-function-[fsharp].md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: Array.distinct<'T> Function (F#)
description: Array.distinct<'T> Function (F#)
keywords: visual f#, f#, functional programming
author: liboz
manager: danielfe
ms.date: 7/20/2016
ms.topic: language-reference
ms.prod: visual-studio-dev14
ms.technology: devlang-fsharp
ms.assetid: 46f7d775-a72b-4de7-902c-9eb4b8b44b1b
---

# Array.distinct<'T> Function (F#)

Returns an array that contains no duplicate entries according to generic hash and equality comparisons on the entries. If an element occurs multiple times in the array then the later occurrences are discarded.

**Namespace/Module Path:** Microsoft.FSharp.Collections.Array

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

## Syntax

```fsharp
// Signature:
Array.distinct : 'T [] -> 'T [] (requires equality)

// Usage:
Array.distinct source
```

#### Parameters
*source*
Type: **'T [[]](https://msdn.microsoft.com/library/def20292-9aae-4596-9275-b94e594f8493)**

The input array.

## Exceptions
|Exception|Condition|
|----|----|
|[ArgumentNullException](https://msdn.microsoft.com/library/system.argumentnullexception.aspx)|Thrown when the input array is null|

## Return Value
The result array.

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

## Example
The following example demonstrates the use of Array.distinct. The example generates the binary representation of a number as a array. It then determines that the only unique numbers are 0 and 1.

[!code-fsharp[Main](snippets/fsarrays/snippet74.fs)]

**Output**
```
[|1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0|]
[|1; 0|]
```

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

## Version Information
**F# Core Library Versions**

Supported in: 4.0, Portable

## See Also
[Collections.Array Module &#40;F&#35;&#41;](Collections.Array-Module-%5BFSharp%5D.md)

[Microsoft.FSharp.Collections Namespace &#40;F&#35;&#41;](Microsoft.FSharp.Collections-Namespace-%5BFSharp%5D.md)
1 change: 1 addition & 0 deletions docs/conceptual/collections.array-module-[fsharp].md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ For an overview of arrays in F#, see [Arrays &#40;F&#35;&#41;](Arrays-%5BFSharp%
|[`copy`](https://msdn.microsoft.com/library/9d0202f1-1ea0-475e-9d66-4f8ccc3c5b5f)<br />**: 'T -&gt; 'T []**|Creates an array that contains the elements of the supplied array.|
|[`countBy`](array.countby['t,'key]-function-[fsharp].md)<br />**: ('T -&gt; 'Key) -&gt; 'T [] -&gt; ('Key &#42; int) []**|Applies a key-generating function to each element of an array and returns am array yielding unique keys and their number of occurrences in the original array.|
|[`create`](https://msdn.microsoft.com/library/e848c8d6-1142-4080-9727-8dacc26066be)<br />**: int -&gt; 'T -&gt; 'T []**|Creates an array whose elements are all initially the supplied value.|
|[`distinct`](array.distinct%5B't%5D-function-%5Bfsharp%5D.md)<br />**: 'T [] -&gt; 'T []**|Returns an array that contains no duplicate entries according to generic hash and equality comparisons on the entries. If an element occurs multiple times in the array then the later occurrences are discarded.|
|[`empty`](https://msdn.microsoft.com/library/c3694b92-1c16-4c54-9bf2-fe398fadce32)<br />**: 'T []**|Returns an empty array of the given type.|
|[`exists`](https://msdn.microsoft.com/library/8e47ad6c-c065-4876-8cb4-ec960ec3e5c9)<br />**: ('T -&gt; bool) -&gt; 'T [] -&gt; bool**|Tests whether any element of an array satisfies the supplied predicate.|
|[`exists2`](https://msdn.microsoft.com/library/2e384a6a-f99d-4e23-b677-250ffbc1dd8e)<br />**: ('T1 -&gt; 'T2 -&gt; bool) -&gt; 'T1 [] -&gt; 'T2 [] -&gt; bool**|Tests whether any pair of corresponding elements of two arrays satisfy the supplied condition.|
Expand Down
1 change: 1 addition & 0 deletions docs/conceptual/collections.list-module-[fsharp].md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ For an overview of lists in F#, see [Lists &#40;F&#35;&#41;](Lists-%5BFSharp%5D.
|[concat](https://msdn.microsoft.com/library/c5afd433-8764-4ea8-a6a8-937fb4d77c4c)<br />**: seq&lt;'T list&gt; -&gt; 'T list**|Returns a new list that contains the elements of each the lists in order.|
|[contains](list.contains%5B't%5D-function-%5Bfsharp%5D.md)<br />**: 'T -&gt; 'T list -&gt; bool**|Evaluates to `true` if the given element is in the input list.|
|[countBy](list.countby%5B't,'key%5D-function-%5Bfsharp%5D.md)<br />**: ('T -&gt; 'Key) -&gt; 'T list -&gt; ('Key &#42; int) list**|Applies a key-generating function to each element of a list and returns a list yielding unique keys and their number of occurrences in the original list.|
|[distinct](list.distinct%5B't%5D-function-%5Bfsharp%5D.md)<br />**: 'T -&gt; 'T list**|Returns a list that contains no duplicate entries according to generic hash and equality comparisons on the entries. If an element occurs multiple times in the list then the later occurrences are discarded.|
|[empty](https://msdn.microsoft.com/library/bb4cb501-3429-47c1-8d5f-71180d3bded7)<br />**: 'T list**|Returns an empty list of the given type.|
|[exists](https://msdn.microsoft.com/library/15a3ebd5-98f0-44c0-8220-7dedec3e68a8)<br />**: ('T -&gt; bool) -&gt; 'T list -&gt; bool**|Tests if any element of the list satisfies the given predicate.|
|[exists2](https://msdn.microsoft.com/library/7532b39e-3f4f-4534-a60b-d7721dc6fa7e)<br />**: ('T1 -&gt; 'T2 -&gt; bool) -&gt; 'T1 list -&gt; 'T2 list -&gt; bool**|Tests if any pair of corresponding elements of the lists satisfies the given predicate.|
Expand Down
71 changes: 71 additions & 0 deletions docs/conceptual/list.distinct['t]-function-[fsharp].md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: List.distinct<'T> Function (F#)
description: List.distinct<'T> Function (F#)
keywords: visual f#, f#, functional programming
author: liboz
manager: danielfe
ms.date: 7/20/2016
ms.topic: language-reference
ms.prod: visual-studio-dev14
ms.technology: devlang-fsharp
ms.assetid: ea0e0598-c63d-4973-8e73-4e3544c6e47d
---

# List.distinct<'T> Function (F#)

Returns a list that contains no duplicate entries according to generic hash and equality comparisons on the entries. If an element occurs multiple times in the list then the later occurrences are discarded.

**Namespace/Module Path:** Microsoft.FSharp.Collections.List

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

## Syntax

```fsharp
// Signature:
List.distinct : 'T list -> 'T list (requires equality)

// Usage:
List.distinct source
```

#### Parameters
*source*
Type: **'T**[list](https://msdn.microsoft.com/library/c627b668-477b-4409-91ed-06d7f1b3e4a7)

The input list.

## Exceptions
|Exception|Condition|
|----|----|
|[ArgumentNullException](https://msdn.microsoft.com/library/system.argumentnullexception.aspx)|Thrown when the input list is null|

## Return Value
The result list.

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

## Example
The following example demonstrates the use of List.distinct. The example generates the binary representation of a number as a list. It then determines that the only unique numbers are 0 and 1.

[!code-fsharp[Main](snippets/fslists/snippet70.fs)]

**Output**
```
[1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0]
[1; 0]
```

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

## Version Information
**F# Core Library Versions**

Supported in: 4.0, Portable

## See Also
[Collections.List Module &#40;F&#35;&#41;](Collections.List-Module-%5BFSharp%5D.md)

[Microsoft.FSharp.Collections Namespace &#40;F&#35;&#41;](Microsoft.FSharp.Collections-Namespace-%5BFSharp%5D.md)
6 changes: 2 additions & 4 deletions docs/conceptual/seq.distinct['t]-function-[fsharp].md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Returns a sequence that contains no duplicate entries according to generic hash

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


## Syntax

```fsharp
Expand All @@ -34,7 +33,6 @@ Seq.distinct source
*source*
Type: [seq](https://msdn.microsoft.com/library/2f0c87c6-8a0d-4d33-92a6-10d1d037ce75)**&lt;'T&gt;**


The input sequence.

## Exceptions
Expand All @@ -53,6 +51,7 @@ The following example demonstrates the use of Seq.distinct. The example generate

[!code-fsharp[Main](snippets/fssequences/snippet22.fs)]

**Output**
```
[1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0]
seq [1; 0]
Expand All @@ -61,7 +60,6 @@ seq [1; 0]
## Platforms
Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2


## Version Information
**F# Core Library Versions**

Expand All @@ -70,4 +68,4 @@ Supported in: 2.0, 4.0, Portable
## See Also
[Collections.Seq Module &#40;F&#35;&#41;](Collections.Seq-Module-%5BFSharp%5D.md)

[Microsoft.FSharp.Collections Namespace &#40;F&#35;&#41;](Microsoft.FSharp.Collections-Namespace-%5BFSharp%5D.md)
[Microsoft.FSharp.Collections Namespace &#40;F&#35;&#41;](Microsoft.FSharp.Collections-Namespace-%5BFSharp%5D.md)
10 changes: 10 additions & 0 deletions docs/conceptual/snippets/fsarrays/snippet74.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let binary n =
let rec generateBinary n =
if (n / 2 = 0) then [n]
else (n % 2) :: generateBinary (n / 2)
generateBinary n |> List.rev |> Array.ofList

printfn "%A" (binary 1024)

let resultArray = Array.distinct (binary 1024)
printfn "%A" resultArray
10 changes: 10 additions & 0 deletions docs/conceptual/snippets/fslists/snippet70.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let binary n =
let rec generateBinary n =
if (n / 2 = 0) then [n]
else (n % 2) :: generateBinary (n / 2)
generateBinary n |> List.rev

printfn "%A" (binary 1024)

let resultList = List.distinct (binary 1024)
printfn "%A" resultList
1 change: 0 additions & 1 deletion docs/conceptual/snippets/fssequences/snippet22.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

let binary n =
let rec generateBinary n =
if (n / 2 = 0) then [n]
Expand Down