Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

extra-lists

Package Overview
Dependencies
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extra-lists - npm Package Compare versions

Comparing version 2.0.79 to 2.0.80

example.js

20

index.d.ts

@@ -11,7 +11,7 @@ declare module 'extra-lists' {

/**
* Lists cartesian product of maps.
* @param xs maps
* @param fn map function (vs, i)
* Lists cartesian product of lists.
* @param xs lists
* @param fm map function (vs, i)
*/
export function cartesianProduct<T, U, V = U>(xs: Map<T, U>[], fn?: mapFn<number, Map<T, U>, Map<T, U> | V>): IterableIterator<Map<T, U> | V>;
export function cartesianProduct<T, U, V = U>(xs: Lists<T, U>[], fm?: mapFn<number, Lists<T, U>, Lists<T, U> | V>): Iterable<Lists<T, U> | V>;
/**

@@ -161,7 +161,7 @@ * Breaks lists into chunks of given size.

/**
* Checks if maps have no common keys.
* @param x a map
* @param y another map
* Checks if lists have no common keys.
* @param x lists
* @param y another lists
*/
export function isDisjoint<T, U>(x: Map<T, U>, y: Map<T, U>): boolean;
export function isDisjoint<T, U>(x: Lists<T, U>, y: Lists<T, U>): boolean;
/**

@@ -236,5 +236,5 @@ * Checks if lists is empty.

* @param x lists
* @param fn map function (v, k, x)
* @param fm map function (v, k, x)
s */
export function map<T, U, V>(x: Lists<T, U>, fn: mapFn<T, U, V>): Generator<never, void, unknown>;
export function map<T, U, V>(x: Lists<T, U>, fm: mapFn<T, U, V>): Generator<never, any[][], unknown>;
/**

@@ -241,0 +241,0 @@ * Finds largest value.

@@ -9,4 +9,22 @@ 'use strict';

function* cartesianProduct(xs, fn = null) {
var fn = fn || id;
function keys(x) {
return x[0];
}
function values(x) {
return x[1];
}
function* entries(x) {
var vi = values(x)[Symbol.iterator]();
for (var k of keys(x))
yield [k, vi.next().value];
}
function id$1(v) {
return v;
}
function* cartesianProduct(xs, fm = null) {
var fm = fm || id$1;
var XS = xs.length;

@@ -23,3 +41,3 @@ var kss = xs.map(x => [...x.keys()]);

}
yield fn(a, j, null);
yield fm(a, j, null);
for (var r = XS - 1; r >= 0; r--) {

@@ -36,257 +54,2 @@ is[r]++;

function keys(x) {
return x[0];
}
function values(x) {
return x[1];
}
function someIf(x) {
for (var v of x)
if (v)
return true;
return false;
}
function someTest(x, fn) {
var i = -1;
for (var v of x)
if (fn(v, ++i, x))
return true;
return false;
}
function some(x, fn = null) {
if (fn)
return someTest(x, fn);
else
return someIf(x);
}
function id$1(v) {
return v;
}
function chunk(x, n = 1, s = n) {
var a = [];
for (var i = 0, I = x.length; i < I; i += s)
a.push(x.slice(i, i + n));
return a;
}
function some$1(x, fn) {
return some(x, fn);
}
function value(x, r = Math.random()) {
var i = Math.floor(r * x.length);
return x[i];
}
function zip(xs, fm = null, ft = null, vd) {
var fm = fm || id$1, ft = ft || some$1;
var X = xs.length, a = [];
if (X === 0)
return a;
var ds = new Array(X).fill(false);
var ls = xs.map(x => x.length);
for (var i = 0;; i++) {
for (var j = 0, vs = []; j < X; j++) {
ds[j] = i >= ls[j];
vs[j] = ds[j] ? vd : xs[j][i];
}
if (ft(ds))
break;
a.push(fm(vs, i, null));
}
return a;
}
function chunk$1(x, n = 1, s = n) {
var kss = chunk([...keys(x)], n, s);
var vss = chunk([...values(x)], n, s);
return zip([kss, vss]);
}
function* entries(x) {
var vi = values(x)[Symbol.iterator]();
for (var k of keys(x))
yield [k, vi.next().value];
}
function id$2(v) {
return v;
}
function cmp(a, b) {
return a < b ? -1 : (a > b ? 1 : 0);
}
function unionKeys(...xs) {
var a = new Set();
for (var x of xs) {
for (var [k] of x)
a.add(k);
}
return a;
}
function compare(x, y, fc = null, fm = null) {
var fc = fc || cmp, fm = fm || id$2;
var ks = unionKeys(x, y);
for (var k of ks) {
if (!x.has(k))
return -1;
if (!y.has(k))
return 1;
var u = fm(x.get(k), k, x);
var v = fm(y.get(k), k, y);
var c = fc(u, v);
if (c !== 0)
return c;
}
return 0;
}
function compare$1(x, y, fc = null, fm = null) {
return compare(new Map(x), new Map(y), fc, fm);
}
function get$1(x, k) {
for (var [j, u] of x)
if (k === j)
return u;
}
function compare$2(x, y, fc, fm) {
return compare$1(entries(x), entries(y), fc, fm);
}
const END = Number.MAX_SAFE_INTEGER;
function is(v) {
return v != null && typeof v[Symbol.iterator] === 'function';
}
function id$3(v) {
return v;
}
function cmp$1(a, b) {
return a < b ? -1 : (a > b ? 1 : 0);
}
function* concat(...xs) {
for (var x of xs)
yield* x;
}
function* slicePos(x, i, I) {
var k = -1;
for (var v of x) {
if (++k >= I)
break;
if (k >= i)
yield v;
}
}
function* slicePosNeg(x, i, I) {
var j = 0, k = -1;
var a = [], A = -I;
for (var v of x) {
if (++k < i)
continue;
if (a.length >= A)
yield a[j];
a[j] = v;
j = (j + 1) % A;
}
}
function* sliceNeg(x, i, I) {
var j = 0, n = 0;
var a = [], A = -i;
for (var v of x) {
a[j] = v;
j = (j + 1) % A;
n++;
}
if (n < A)
return;
var I = I < 0 ? I : Math.min(I - n, 0);
var n = Math.max(I - i, 0);
var J = Math.max(j + n - A, 0);
yield* a.slice(j, j + n);
yield* a.slice(0, J);
}
function* slice(x, i = 0, I = END) {
if (i >= 0 && I >= 0)
yield* slicePos(x, i, I);
else if (i >= 0 && I < 0)
yield* slicePosNeg(x, i, I);
else
yield* sliceNeg(x, i, I);
}
function size(x, i = 0, I = END) {
var j = -1, n = 0;
for (var _ of x)
if (++j >= i && j < I)
n++;
return n;
}
function* map(x, fn) {
var i = -1;
for (var v of x)
yield fn(v, ++i, x);
}
function* drop(x, n = 1) {
yield* slice(x, n);
}
function isList(v) {
return is(v) && typeof v !== 'string';
}
function head(x, vd) {
for (var v of x)
return v;
return vd;
}
function searchValue(x, v, fc = null, fm = null) {
var fc = fc || cmp$1, fm = fm || id$3;
var v1 = fm(v, 0, null), i = -1;
for (var u of x) {
var u1 = fm(u, ++i, x);
if (fc(u1, v1) === 0)
return i;
}
return -1;
}
function isValue(x, v, fc = null, fm = null) {
return searchValue(x, v, fc, fm) >= 0;
}
function isEmpty(x) {
for (var _ of x)
return false;
return true;
}
function* take(x, n = 1) {
yield* slice(x, 0, n);
}
function concat$1(...xs) {
var ks = concat(...xs.map(keys));
var vs = concat(...xs.map(values));
return [ks, vs];
}
function id$4(v) {
return v;
}
function filterAt(x, ks) {

@@ -299,3 +62,3 @@ var a = new Map();

function cmp$2(a, b) {
function cmp(a, b) {
return a < b ? -1 : (a > b ? 1 : 0);

@@ -321,3 +84,3 @@ }

function countAs(x, fm) {
var fm = fm || id$4;
var fm = fm || id$1;
var a = new Map();

@@ -465,3 +228,3 @@ for (var [k, v] of x) {

function intersection(x, y, fc = null) {
var fc = fc || id$4;
var fc = fc || id$1;
var a = new Map();

@@ -475,3 +238,3 @@ for (var [k, v] of y)

function isSubmap(x, y, fc = null, fm = null) {
var fc = fc || cmp$2, fm = fm || id$4;
var fc = fc || cmp, fm = fm || id$1;
for (var [k, v] of y) {

@@ -488,4 +251,4 @@ if (!x.has(k))

function searchValue$1(x, v, fc = null, fm = null) {
var fc = fc || cmp$2, fm = fm || id$4;
function searchValue(x, v, fc = null, fm = null) {
var fc = fc || cmp, fm = fm || id$1;
var v1 = fm(v, null, null);

@@ -507,3 +270,3 @@ for (var [k, u] of x) {

function range(x, fc = null, fm = null) {
var fc = fc || cmp$2, fm = fm || id$4;
var fc = fc || cmp, fm = fm || id$1;
var mk, mu, mv;

@@ -561,3 +324,3 @@ var nk, nu, nv;

function searchValueAll(x, v, fc = null, fm = null) {
var fc = fc || cmp$2, fm = fm || id$4;
var fc = fc || cmp, fm = fm || id$1;
var v1 = fm(v, null, x), a = [];

@@ -572,3 +335,3 @@ for (var [k, u] of x) {

function some$1$1(x, ft) {
function some$1(x, ft) {
return scanUntil(x, ft) !== undefined;

@@ -602,3 +365,3 @@ }

function union$(x, y, fc = null) {
var fc = fc || id$4;
var fc = fc || id$1;
for (var [k, v] of y) {

@@ -618,462 +381,313 @@ if (!x.has(k))

/**
* Counts values which satisfy a test.
* @param x lists
* @param ft test function (v, k, x)
* Lists cartesian product of lists.
* @param xs lists
* @param fm map function (vs, i)
*/
function count$1(x, ft) {
return count(entries(x), ft);
function* cartesianProduct$1(xs, fm = null) {
var fm = fm || id, ys = xs.map(x => new Map(entries(x)));
yield* cartesianProduct(ys, (vs, i) => fm([vs.keys(), vs.values()], i, null));
}
/**
* Counts occurrences of values.
* @param x lists
* @param fm map function (v, k, x)
* @returns Map {value => count}
*/
function countAs$1(x, fm = null) {
return countAs(entries(x), fm);
function someIf(x) {
for (var v of x)
if (v)
return true;
return false;
}
/**
* Gives entries of lists not present in another.
* @param x lists
* @param y another lists
*/
function difference(x, y) {
var a = fromLists(x);
for (var k of keys(y))
a.delete(k);
return [a.keys(), a.values()];
function someTest(x, fn) {
var i = -1;
for (var v of x)
if (fn(v, ++i, x))
return true;
return false;
}
function some(x, fn = null) {
if (fn)
return someTest(x, fn);
else
return someIf(x);
}
/**
* Removes first n entries.
* @param x lists
* @param n number of entries (1)
*/
function drop$1(x, n = 1) {
var ks = drop(keys(x), n);
var vs = drop(values(x), n);
return [ks, vs];
function id$1$1(v) {
return v;
}
/**
* Picks an arbitrary entry.
* @param x lists
* @param r random seed 0->1
*/
function entry(x, r = Math.random()) {
return value([...entries(x)], r);
function chunk(x, n = 1, s = n) {
var a = [];
for (var i = 0, I = x.length; i < I; i += s)
a.push(x.slice(i, i + n));
return a;
}
/**
* Checks if all values satisfy a test.
* @param x lists
* @param ft test function (v, k ,x)
*/
function every$1(x, ft) {
return every(entries(x), ft);
function some$1$1(x, fn) {
return some(x, fn);
}
/**
* Keeps entries which pass a test.
* @param x lists
* @param ft test function (v, k, x)
*/
function filter(x, ft) {
var ks = [], vs = [];
for (var [k, v] of entries(x))
if (ft(v, k, x)) {
ks.push(k);
vs.push(v);
}
return [vs, ks];
function value(x, r = Math.random()) {
var i = Math.floor(r * x.length);
return x[i];
}
/**
* Gets lists with given keys.
* @param x lists
* @param ks keys
*/
function filterAt$1(x, ks) {
var js = [], us = [];
for (var [k, v] of entries(x))
if (ks.includes(k)) {
js.push(k);
us.push(v);
function zip(xs, fm = null, ft = null, vd) {
var fm = fm || id$1$1, ft = ft || some$1$1;
var X = xs.length, a = [];
if (X === 0)
return a;
var ds = new Array(X).fill(false);
var ls = xs.map(x => x.length);
for (var i = 0;; i++) {
for (var j = 0, vs = []; j < X; j++) {
ds[j] = i >= ls[j];
vs[j] = ds[j] ? vd : xs[j][i];
}
return [js, us];
if (ft(ds))
break;
a.push(fm(vs, i, null));
}
return a;
}
/**
* Finds a value passing a test.
* Breaks lists into chunks of given size.
* @param x lists
* @param ft test function (v, k, x)
* @param n chunk size (1)
* @param s chunk step (n)
*/
function find$1(x, ft) {
return find(entries(x), ft);
function chunk$1(x, n = 1, s = n) {
var kss = chunk([...keys(x)], n, s);
var vss = chunk([...values(x)], n, s);
return zip([kss, vss]);
}
/**
* Finds values passing a test.
* @param x lists
* @param ft test function (v, k, x)
*/
function findAll$1(x, ft) {
return findAll(entries(x), ft);
function id$2(v) {
return v;
}
/**
* Checks if value is lists.
* @param v value
*/
function is$1(v) {
return Array.isArray(v) && v.length === 2 && isList(v[0]) && isList(v[1]);
function cmp$1(a, b) {
return a < b ? -1 : (a > b ? 1 : 0);
}
function flatTo(x, n, fm, ft, a) {
for (var [k, v] of entries(x)) {
var v1 = fm(v, k, x);
if (n !== 0 && ft(v1, k, x))
flatTo(v1, n - 1, fm, ft, a);
else
a.set(k, v1);
function unionKeys(...xs) {
var a = new Set();
for (var x of xs) {
for (var [k] of x)
a.add(k);
}
return a;
}
/**
* Flattens nested lists to given depth.
* @param x nested lists
* @param n maximum depth (-1)
* @param fm map function (v, k, x)
* @param ft test function (v, k, x)
*/
function flat(x, n = -1, fm = null, ft = null) {
var fm = fm || id, ft = ft || is$1;
var a = flatTo(x, n, fm, ft, new Map());
return [a.keys(), a.values()];
}
/**
* Flattens nested lists, using map function.
* @param x nested lists
* @param fm map function (v, k, x)
* @param ft test function (v, k, x)
*/
function flatMap(x, fm = null, ft = null) {
var fm = fm || id, ft = ft || is$1;
var a = new Map();
for (var [k, v] of entries(x)) {
var v1 = fm(v, k, x);
if (ft(v1, k, x))
concat$(a, entries(v1));
else
a.set(k, v1);
function compare(x, y, fc = null, fm = null) {
var fc = fc || cmp$1, fm = fm || id$2;
var ks = unionKeys(x, y);
for (var k of ks) {
if (!x.has(k))
return -1;
if (!y.has(k))
return 1;
var u = fm(x.get(k), k, x);
var v = fm(y.get(k), k, y);
var c = fc(u, v);
if (c !== 0)
return c;
}
return [a.keys(), a.values()];
return 0;
}
/**
* Calls a function for each value.
* @param x lists
* @param fc called function (v, k, x)
* Compares two entries.
* @param x entries
* @param y another entries
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
* @returns x=y: 0, otherwise: -ve/+ve
*/
function forEach$1(x, fc) {
forEach(entries(x), fc);
function compare$1(x, y, fc = null, fm = null) {
return compare(new Map(x), new Map(y), fc, fm);
}
/**
* Creates lists from entries.
* @param es entries
*/
function fromEntries(es) {
var a = new Map(es);
return [a.keys(), a.values()];
function get$1(x, k) {
for (var [j, u] of x)
if (k === j)
return u;
}
/**
* Gets value at key.
* Compares two lists.
* @param x lists
* @param k key
* @param y another lists
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
* @returns x=y: 0, otherwise: -ve/+ve
*/
function get$2(x, k) {
return get$1(entries(x), k);
function compare$2(x, y, fc, fm) {
return compare$1(entries(x), entries(y), fc, fm);
}
/**
* Gets values at keys.
* @param x lists
* @param ks keys
*/
function getAll$2(x, ks) {
return getAll$1(new Map(entries(x)), ks);
}
const END = Number.MAX_SAFE_INTEGER;
/**
* Gets first entry.
* @param x lists
* @param ed default entry
*/
function head$1(x, ed = []) {
return head(entries(x), ed);
function is(v) {
return v != null && typeof v[Symbol.iterator] === 'function';
}
/**
* Gives entries present in both lists.
* @param x lists
* @param y another lists
* @param fc combine function (a, b)
*/
function intersection$1(x, y, fc = null) {
var a = intersection(new Map(entries(x)), entries(y), fc);
return [a.keys(), a.values()];
function id$3(v) {
return v;
}
/**
* Checks if maps have no common keys.
* @param x a map
* @param y another map
*/
function isDisjoint(x, y) {
for (var k of x.keys())
if (y.has(k))
return false;
return true;
function cmp$2(a, b) {
return a < b ? -1 : (a > b ? 1 : 0);
}
/**
* Checks if lists is empty.
* @param x lists
*/
function isEmpty$1(x) {
return isEmpty(keys(x));
function* concat(...xs) {
for (var x of xs)
yield* x;
}
/**
* Compares two values.
* @param a a value
* @param b another value
* @returns a<b: -ve, a=b: 0, a>b: +ve
*/
function cmp$3(a, b) {
return a < b ? -1 : (a > b ? 1 : 0);
function* slicePos(x, i, I) {
var k = -1;
for (var v of x) {
if (++k >= I)
break;
if (k >= i)
yield v;
}
}
/**
* Checks if map has an entry.
* @param x a map
* @param e entry?
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
*/
function isEntry(x, e, fc = null, fm = null) {
var fc = fc || cmp$3, fm = fm || id, [k, v] = e;
var [k, v] = e, u = get$2(x, k);
return fc(fm(u, k, x), v) === 0;
function* slicePosNeg(x, i, I) {
var j = 0, k = -1;
var a = [], A = -I;
for (var v of x) {
if (++k < i)
continue;
if (a.length >= A)
yield a[j];
a[j] = v;
j = (j + 1) % A;
}
}
function* sliceNeg(x, i, I) {
var j = 0, n = 0;
var a = [], A = -i;
for (var v of x) {
a[j] = v;
j = (j + 1) % A;
n++;
}
if (n < A)
return;
var I = I < 0 ? I : Math.min(I - n, 0);
var n = Math.max(I - i, 0);
var J = Math.max(j + n - A, 0);
yield* a.slice(j, j + n);
yield* a.slice(0, J);
}
function* slice(x, i = 0, I = END) {
if (i >= 0 && I >= 0)
yield* slicePos(x, i, I);
else if (i >= 0 && I < 0)
yield* slicePosNeg(x, i, I);
else
yield* sliceNeg(x, i, I);
}
/**
* Checks if two lists are equal.
* @param x lists
* @param y another lists
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
*/
function isEqual(x, y, fc = null, fm = null) {
return compare$2(x, y, fc, fm) === 0;
function size(x, i = 0, I = END) {
var j = -1, n = 0;
for (var _ of x)
if (++j >= i && j < I)
n++;
return n;
}
/**
* Checks if lists has a key.
* @param x lists
* @param k key?
*/
function isKey(x, k) {
return isValue(keys(x), k);
function* map(x, fn) {
var i = -1;
for (var v of x)
yield fn(v, ++i, x);
}
/**
* Checks if lists has a submap.
* @param x lists
* @param y submap?
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
*/
function isSubmap$1(x, y, fc = null, fm = null) {
return isSubmap(new Map(entries(x)), entries(y), fc, fm);
function* drop(x, n = 1) {
yield* slice(x, n);
}
/**
* Finds key with given value.
* @param x lists
* @param v search value
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
*/
function searchValue$2(x, v, fc = null, fm = null) {
return searchValue$1(entries(x), v, fc, fm);
function isList(v) {
return is(v) && typeof v !== 'string';
}
/**
* Checks if lists has a value.
* @param x lists
* @param v value?
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
*/
function isValue$1(x, v, fc = null, fm = null) {
return searchValue$2(x, v, fc, fm) !== undefined;
function head(x, vd) {
for (var v of x)
return v;
return vd;
}
/**
* Joins values together.
* @param x lists
* @param sep separator (,)
* @param asc associator (=)
*/
function join$1(x, sep = ',', asc = '=') {
return join(entries(x), sep, asc);
function searchValue$1(x, v, fc = null, fm = null) {
var fc = fc || cmp$2, fm = fm || id$3;
var v1 = fm(v, 0, null), i = -1;
for (var u of x) {
var u1 = fm(u, ++i, x);
if (fc(u1, v1) === 0)
return i;
}
return -1;
}
/**
* Picks an arbitrary key.
* @param x lists
* @param r random seed 0->1
*/
function key(x, r = Math.random()) {
return value([...keys(x)], r);
function isValue(x, v, fc = null, fm = null) {
return searchValue$1(x, v, fc, fm) >= 0;
}
/**
* Gets size of lists.
* @param x lists
*/
function size$1(x) {
return size(keys(x));
function isEmpty(x) {
for (var _ of x)
return false;
return true;
}
/**
* Gets size of lists.
* @param x lists
*/
function length(x) {
return size$1(x);
function* take(x, n = 1) {
yield* slice(x, 0, n);
}
/**
* Updates values based on map function.
* @param x lists
* @param fn map function (v, k, x)
s */
function* map$1(x, fn) {
function concat$1(...xs) {
var ks = concat(...xs.map(keys));
var vs = concat(...xs.map(values));
return [ks, vs];
}
/**
* Finds smallest and largest entries.
* @param x lists
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
* @returns [smallest, largest]
*/
function range$1(x, fc = null, fm = null) {
return range(entries(x), fc, fm);
function count$1(x, ft) {
return count(entries(x), ft);
}
/**
* Finds largest value.
* @param x lists
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
* @returns [key, value]
*/
function max(x, fc = null, fm = null) {
return range$1(x, fc, fm)[1];
function countAs$1(x, fm = null) {
return countAs(entries(x), fm);
}
/**
* Finds smallest entry.
* @param x lists
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
* @returns [key, value]
*/
function min(x, fc = null, fm = null) {
return range$1(x, fc, fm)[0];
function difference(x, y) {
var a = fromLists(x);
for (var k of keys(y))
a.delete(k);
return [a.keys(), a.values()];
}
/**
* Segregates values by test result.
* @param x lists
* @param ft test function (v, k, x)
* @returns [satisfies, doesnt]
*/
function partition(x, ft) {
var tk = [], tv = [], fk = [], fv = [];
for (var [k, v] of entries(x)) {
if (ft(v, k, x)) {
tk.push(k);
tv.push(v);
}
else {
fk.push(k);
fv.push(v);
}
}
return [[tk, tv], [fk, fv]];
function drop$1(x, n = 1) {
var ks = drop(keys(x), n);
var vs = drop(values(x), n);
return [ks, vs];
}
/**
* Segregates values by similarity.
* @param x lists
* @param fm map function (v, k, x)
* @returns Map {key => values}
*/
function partitionAs(x, fm = null) {
var fm = fm || id, a = new Map();
for (var [k, v] of entries(x)) {
var v1 = fm(v, k, x);
if (!a.has(v1))
a.set(v1, [[], []]);
var [ak, av] = a.get(v1);
ak.push(k);
av.push(v);
}
return a;
function entry(x, r = Math.random()) {
return value([...entries(x)], r);
}
/**
* Reduces values to a single value.
* @param x lists
* @param fr reduce function (acc, v, k, x)
* @param acc initial value
*/
function reduce$1(x, fr, acc) {
var A = arguments.length, es = entries(x);
return A > 2 ? reduce(es, fr, acc) : reduce(es, fr);
function every$1(x, ft) {
return every(entries(x), ft);
}
/**
* Discards entries which pass a test.
* @param x lists
* @param ft test function (v, k, x)
*/
function reject(x, ft) {
function filter(x, ft) {
var ks = [], vs = [];
for (var [k, v] of entries(x))
if (!ft(v, k, x)) {
if (ft(v, k, x)) {
ks.push(k);
vs.push(v);
}
return [ks, vs];
return [vs, ks];
}
/**
* Gets lists without given keys.
* @param x lists
* @param ks keys
*/
function rejectAt(x, ks) {
function filterAt$1(x, ks) {
var js = [], us = [];
for (var [k, v] of entries(x))
if (!ks.includes(k)) {
if (ks.includes(k)) {
js.push(k);

@@ -1085,165 +699,66 @@ us.push(v);

/**
* Deletes an entry.
* @param x lists
* @param k key
*/
function remove(x, k) {
var ks = [], vs = [];
for (var [j, u] of entries(x))
if (j !== k) {
ks.push(j);
vs.push(u);
}
return [ks, vs];
function find$1(x, ft) {
return find(entries(x), ft);
}
/**
* Finds key of first entry not passing a test.
* @param x lists
* @param ft test function (v, k, x)
*/
function scanUntil$1(x, ft) {
return scanUntil(entries(x), ft);
function findAll$1(x, ft) {
return findAll(entries(x), ft);
}
/**
* Finds key of first entry not passing a test.
* @param x lists
* @param ft test function (v, k, x)
*/
function scanWhile$1(x, ft) {
return scanWhile(entries(x), ft);
function is$1(v) {
return Array.isArray(v) && v.length === 2 && isList(v[0]) && isList(v[1]);
}
/**
* Finds key of an entry passing a test.
* @param x lists
* @param ft test function (v, k, x)
*/
function search$1(x, ft) {
return search(entries(x), ft);
function flatTo(x, n, fm, ft, a) {
for (var [k, v] of entries(x)) {
var v1 = fm(v, k, x);
if (n !== 0 && ft(v1, k, x))
flatTo(v1, n - 1, fm, ft, a);
else
a.set(k, v1);
}
return a;
}
/**
* Finds keys of entries passing a test.
* @param x lists
* @param ft test function (v, k, x)
*/
function searchAll$1(x, ft) {
return searchAll(entries(x), ft);
function flat(x, n = -1, fm = null, ft = null) {
var fm = fm || id, ft = ft || is$1;
var a = flatTo(x, n, fm, ft, new Map());
return [a.keys(), a.values()];
}
/**
* Finds keys with given value.
* @param x lists
* @param v search value
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
*/
function searchValueAll$1(x, v, fc = null, fm = null) {
return searchValueAll(entries(x), v, fc, fm);
}
/**
* Sets value at key.
* @param x lists
* @param k key
* @param v value
*/
function set(x, k, v) {
var ks = [], vs = [];
for (var [j, u] of entries(x)) {
ks.push(j);
vs.push(j === k ? v : u);
function flatMap(x, fm = null, ft = null) {
var fm = fm || id, ft = ft || is$1;
var a = new Map();
for (var [k, v] of entries(x)) {
var v1 = fm(v, k, x);
if (ft(v1, k, x))
concat$(a, entries(v1));
else
a.set(k, v1);
}
return [ks, vs];
return [a.keys(), a.values()];
}
/**
* Removes first entry.
* @param x lists
*/
function shift(x) {
return drop$1(x, 1);
function forEach$1(x, fc) {
forEach(entries(x), fc);
}
/**
* Checks if any value satisfies a test.
* @param x lists
* @param ft test function (v, k, x)
*/
function some$2(x, ft = null) {
return some$1$1(entries(x), ft);
}
/**
* Picks an arbitrary submap.
* @param x lists
* @param n number of entries (-1 => any)
* @param r random seed 0->1
*/
function submap$1(x, n = -1, r = Math.random()) {
var a = submap(new Map(entries(x)), n, r);
function fromEntries(es) {
var a = new Map(es);
return [a.keys(), a.values()];
}
/**
* Lists all possible submaps.
* @param x lists
* @param n number of entries (-1 => any)
*/
function* submaps$1(x, n = -1) {
for (var a of submaps(new Map(entries(x)), n))
yield [a.keys(), a.values()];
function get$2(x, k) {
return get$1(entries(x), k);
}
/**
* Exchanges two values.
* @param x lists
* @param k a key
* @param l another key
*/
function swap(x, k, l) {
var ks = map(keys(x), j => j === k ? l : (j === l ? k : j));
return [ks, values(x)];
function getAll$2(x, ks) {
return getAll$1(new Map(entries(x)), ks);
}
/**
* Gives entries not present in both lists.
* @param x lists
* @param y another lists
*/
function symmetricDifference$1(x, y) {
var a = symmetricDifference(entries(x), entries(y));
return [a.keys(), a.values()];
function head$1(x, ed = []) {
return head(entries(x), ed);
}
/**
* Gets lists without the first entry.
* @param x lists
*/
function tail(x) {
return drop$1(x, 1);
}
/**
* Keeps first n entries only.
* @param x lists
* @param n number of entries (1)
*/
function take$1(x, n = 1) {
var ks = take(keys(x), n);
var vs = take(values(x), n);
return [ks, vs];
}
/**
* Gives lists present in any lists.
* @param x lists
* @param y another lists
* @param fc combine function (a, b)
*/
function union$1(x, y, fc = null) {
var a = union(entries(x), entries(y), fc);
function intersection$1(x, y, fc = null) {
var a = intersection(new Map(entries(x)), entries(y), fc);
return [a.keys(), a.values()];

@@ -2025,2 +1540,273 @@ }

/**
* Checks if lists have no common keys.
* @param x lists
* @param y another lists
*/
function isDisjoint(x, y) {
return extraSet_31(new Set(keys(x)), keys(y));
}
/**
* Checks if lists is empty.
* @param x lists
*/
function isEmpty$1(x) {
return isEmpty(keys(x));
}
/**
* Compares two values.
* @param a a value
* @param b another value
* @returns a<b: -ve, a=b: 0, a>b: +ve
*/
function cmp$3(a, b) {
return a < b ? -1 : (a > b ? 1 : 0);
}
/**
* Checks if map has an entry.
* @param x a map
* @param e entry?
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
*/
function isEntry(x, e, fc = null, fm = null) {
var fc = fc || cmp$3, fm = fm || id, [k, v] = e;
var [k, v] = e, u = get$2(x, k);
return fc(fm(u, k, x), v) === 0;
}
/**
* Checks if two lists are equal.
* @param x lists
* @param y another lists
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
*/
function isEqual(x, y, fc = null, fm = null) {
return compare$2(x, y, fc, fm) === 0;
}
/**
* Checks if lists has a key.
* @param x lists
* @param k key?
*/
function isKey(x, k) {
return isValue(keys(x), k);
}
/**
* Checks if lists has a submap.
* @param x lists
* @param y submap?
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
*/
function isSubmap$1(x, y, fc = null, fm = null) {
return isSubmap(new Map(entries(x)), entries(y), fc, fm);
}
/**
* Finds key with given value.
* @param x lists
* @param v search value
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
*/
function searchValue$2(x, v, fc = null, fm = null) {
return searchValue(entries(x), v, fc, fm);
}
/**
* Checks if lists has a value.
* @param x lists
* @param v value?
* @param fc compare function (a, b)
* @param fm map function (v, k, x)
*/
function isValue$1(x, v, fc = null, fm = null) {
return searchValue$2(x, v, fc, fm) !== undefined;
}
/**
* Joins values together.
* @param x lists
* @param sep separator (,)
* @param asc associator (=)
*/
function join$1(x, sep = ',', asc = '=') {
return join(entries(x), sep, asc);
}
function key(x, r = Math.random()) {
return value([...keys(x)], r);
}
function size$1(x) {
return size(keys(x));
}
function length(x) {
return size$1(x);
}
function* map$1(x, fm) {
var ks = [], vs = [];
for (var [k, v] of entries(x)) {
ks.push(k);
vs.push(fm(v, k, x));
}
return [ks, vs];
}
function range$1(x, fc = null, fm = null) {
return range(entries(x), fc, fm);
}
function max(x, fc = null, fm = null) {
return range$1(x, fc, fm)[1];
}
function min(x, fc = null, fm = null) {
return range$1(x, fc, fm)[0];
}
function partition(x, ft) {
var tk = [], tv = [], fk = [], fv = [];
for (var [k, v] of entries(x)) {
if (ft(v, k, x)) {
tk.push(k);
tv.push(v);
}
else {
fk.push(k);
fv.push(v);
}
}
return [[tk, tv], [fk, fv]];
}
function partitionAs(x, fm = null) {
var fm = fm || id, a = new Map();
for (var [k, v] of entries(x)) {
var v1 = fm(v, k, x);
if (!a.has(v1))
a.set(v1, [[], []]);
var [ak, av] = a.get(v1);
ak.push(k);
av.push(v);
}
return a;
}
function reduce$1(x, fr, acc) {
var A = arguments.length, es = entries(x);
return A > 2 ? reduce(es, fr, acc) : reduce(es, fr);
}
function reject(x, ft) {
var ks = [], vs = [];
for (var [k, v] of entries(x))
if (!ft(v, k, x)) {
ks.push(k);
vs.push(v);
}
return [ks, vs];
}
function rejectAt(x, ks) {
var js = [], us = [];
for (var [k, v] of entries(x))
if (!ks.includes(k)) {
js.push(k);
us.push(v);
}
return [js, us];
}
function remove(x, k) {
var ks = [], vs = [];
for (var [j, u] of entries(x))
if (j !== k) {
ks.push(j);
vs.push(u);
}
return [ks, vs];
}
function scanUntil$1(x, ft) {
return scanUntil(entries(x), ft);
}
function scanWhile$1(x, ft) {
return scanWhile(entries(x), ft);
}
function search$1(x, ft) {
return search(entries(x), ft);
}
function searchAll$1(x, ft) {
return searchAll(entries(x), ft);
}
function searchValueAll$1(x, v, fc = null, fm = null) {
return searchValueAll(entries(x), v, fc, fm);
}
function set(x, k, v) {
var ks = [], vs = [];
for (var [j, u] of entries(x)) {
ks.push(j);
vs.push(j === k ? v : u);
}
return [ks, vs];
}
function shift(x) {
return drop$1(x, 1);
}
function some$2(x, ft = null) {
return some$1(entries(x), ft);
}
function submap$1(x, n = -1, r = Math.random()) {
var a = submap(new Map(entries(x)), n, r);
return [a.keys(), a.values()];
}
function* submaps$1(x, n = -1) {
for (var a of submaps(new Map(entries(x)), n))
yield [a.keys(), a.values()];
}
function swap(x, k, l) {
var ks = map(keys(x), j => j === k ? l : (j === l ? k : j));
return [ks, values(x)];
}
function symmetricDifference$1(x, y) {
var a = symmetricDifference(entries(x), entries(y));
return [a.keys(), a.values()];
}
function tail(x) {
return drop$1(x, 1);
}
function take$1(x, n = 1) {
var ks = take(keys(x), n);
var vs = take(values(x), n);
return [ks, vs];
}
function union$1(x, y, fc = null) {
var a = union(entries(x), entries(y), fc);
return [a.keys(), a.values()];
}
function unionKeys$1(...xs) {

@@ -2034,3 +1820,3 @@ return extraSet_6(...xs.map(x => keys(x)));

exports.cartesianProduct = cartesianProduct;
exports.cartesianProduct = cartesianProduct$1;
exports.chunk = chunk$1;

@@ -2037,0 +1823,0 @@ exports.compare = compare$2;

{
"name": "extra-lists",
"version": "2.0.79",
"description": "Lists is pair of list of keys, and values.",
"version": "2.0.80",
"description": "Standard utility methods for Lists.<br>",
"main": "index.js",

@@ -21,3 +21,68 @@ "module": "index.mjs",

"extra",
"lists"
"lists",
"cartesianProduct",
"chunk",
"compare",
"concat",
"count",
"countAs",
"difference",
"drop",
"entries",
"entry",
"every",
"filter",
"filterAt",
"find",
"findAll",
"flat",
"flatMap",
"forEach",
"fromEntries",
"get",
"getAll",
"head",
"intersection",
"is",
"isDisjoint",
"isEmpty",
"isEntry",
"isEqual",
"isKey",
"isSubmap",
"isValue",
"join",
"key",
"keys",
"length",
"map",
"max",
"min",
"partition",
"partitionAs",
"range",
"reduce",
"reject",
"rejectAt",
"remove",
"scanUntil",
"scanWhile",
"search",
"searchAll",
"searchValue",
"searchValueAll",
"set",
"shift",
"size",
"some",
"submap",
"submaps",
"swap",
"symmetricDifference",
"tail",
"take",
"union",
"unionKeys",
"value",
"values"
],

@@ -24,0 +89,0 @@ "repository": {

@@ -1,2 +0,2 @@

Standard utility methods for [Lists].<br>
Standard utility methods for [Lists]. [:running:] [:vhs:] [:package:] [:moon:] [:ledger:]
Browserified, minified module: [extra-lists.min].

@@ -54,1 +54,6 @@

[extra-lists.min]: https://www.npmjs.com/package/extra-lists.min
[:running:]: https://npm.runkit.com/extra-lists
[:vhs:]: https://asciinema.org/a/340678
[:package:]: https://www.npmjs.com/package/extra-lists
[:moon:]: https://www.npmjs.com/package/extra-lists.min
[:ledger:]: https://unpkg.com/extra-lists/

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc