permute<T> function
Sorting data
Returns a permutation of the specified iterable
using the keys
.
The returned list contains the corresponding value of the iterable
for
each index in the keys
, in order.
For example:
permute(["a", "b", "c"], [1, 2, 0]); // returns ["b", "c", "a"]
It is acceptable to have more keys than iterable values, and for keys to be duplicated or omitted.
Implementation
List<T?> permute<T>(Iterable<T> iterable, Iterable<int> keys) =>
List.generate(keys.length, (i) {
var k = keys.elementAt(i);
return k < 0 || k >= iterable.length ? null : iterable.elementAt(k);
});