Expand Minimize

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

Returns a list with all elements permuted according to the specified permutation.

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

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

// Signature:
List.permute : (int -> int) -> 'T list -> 'T list

// Usage:
List.permute indexMap list

indexMap

Type: int -> int

The function to map input indices to output indices.

list

Type: 'T list

The input list.

The permuted list.

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

The following code demonstrates how to use List.permute.

let printPermutation n list1 =
    let length = List.length list1
    if (n > 0 && n < length) then
        List.permute (fun index -> (index + n) % length) list1
    else
        list1
    |> printfn "%A" 
let list1 = [ 1 .. 5 ]
// There are 5 valid permutations of list1, with n from 0 to 4. 
for n in 0 .. 4 do
    printPermutation n list1

Output

[1; 2; 3; 4; 5]
[5; 1; 2; 3; 4]
[4; 5; 1; 2; 3]
[3; 4; 5; 1; 2]
[2; 3; 4; 5; 1]

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

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft