Skip to content

partitionAs

Subhajit Sahu edited this page Feb 3, 2021 · 18 revisions

Segregate values by similarity.

Alternatives: partition, partitionAs.
Similar: count, partition.


function partitionAs(x, fm)
// x:  an array
// fm: map function (v, i, x)
const xiterable = require('extra-iterable');

var x = [1, 2, 3, 4];
xiterable.partitionAs(x, v => v % 2 == 0);
// → xiterable.Map(2) { false => [1, 3], true => [2, 4] }

var x = [1, 2, 3, 4, 5];
xiterable.partitionAs(x, v => v % 3);
// → xiterable.Map(3) { 1 => [1, 4], 2 => [2, 5], 0 => [3] }


References

Clone this wiki locally