Permute

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

Parameters

Returns

Func<int, int> indexMap

IEnumerable<T> source

IEnumerable<T>

Usage

Permuting values in a collection

//IEnumerable<int> source = { 1, 2, 3, 4, 5 }

IEnumerable<int> result =
    source.Permute(index => (index + 1) % 5)

//result = { 5, 1, 2, 3, 4 }

Permuting values in a collection

//IEnumerable<int> source = { 1, 2, 3, 4, 5 }

IEnumerable<int> result =
    source.Permute(index => (index + 2) % 5)

//result = { 4, 5, 1, 2, 3 }

Last updated