-
Notifications
You must be signed in to change notification settings - Fork 0
partitionAs
Subhajit Sahu edited this page Jun 18, 2020
·
15 revisions
Segregates values by similarity. 🏃 📼 📦 🌔 📒
Alternatives: partition, partitionAs.
lists.partitionAs(x, [fm]);
// x: lists
// fm: map function (v, k, x)
// --> Map {key => values}
const lists = require('extra-lists');
var x = [['a', 1], ['b', 2], ['c', 3], ['d', 4]];
entries.partitionAs(x, v => v % 2 == 0);
// Map(2) {
// false => Map(2) { 'a' => 1, 'c' => 3 },
// true => Map(2) { 'b' => 2, 'd' => 4 }
// }
var x = [['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]];
entries.partitionAs(x, v => v % 3);
// Map(3) {
// 1 => Map(2) { 'a' => 1, 'd' => 4 },
// 2 => Map(2) { 'b' => 2, 'e' => 5 },
// 0 => Map(1) { 'c' => 3 }
// }