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

Parameters

  • indexMap
    Type: int ->int

    The function to map input indices to output indices.

  • list
    Type: 'Tlist

    The input list.

Return Value

The permuted list.

Remarks

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.

Example

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]

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

Reference

Collections.List Module (F#)

Microsoft.FSharp.Collections Namespace (F#)