Skip to content

partitionAs

Subhajit Sahu edited this page May 19, 2020 · 18 revisions

Segregates values by similarity. 🏃 📼 📦 🌔 📒

Alternatives: partition, partitionAs.
Similar: [group], partition.

iterable.partitionAs(x, [fn], [ths]);
// x:   an iterable
// fn:  map function (v, i, x)
// ths: this argument
// --> Map {key => values}
const iterable = require('extra-iterable');

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

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

references

Clone this wiki locally