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