-
Notifications
You must be signed in to change notification settings - Fork 1
partitionAs
Subhajit Sahu edited this page Jun 15, 2020
·
18 revisions
Segregates values by similarity. 🏃 📼 📦 🌔 📒
Alternatives: partition, partitionAs.
Similar: count, partition.
iterable.partitionAs(x, [fn]);
// x: an iterable
// fn: map function (v, i, x)
// --> 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 ] }