extra-lists
Advanced tools
Comparing version 2.0.84 to 2.0.85
declare module 'extra-lists' { | ||
export type tillFn = (dones: boolean[]) => boolean; | ||
export type reduceFn<T, U, V> = (acc: V, v: U, k: T, x: Lists<T, U>) => V; | ||
@@ -423,4 +424,12 @@ export type calledFn<T, U> = (v: U, k: T, x: Lists<T, U>) => void; | ||
export function values<T, U>(x: Lists<T, U>): Iterable<U>; | ||
/** | ||
* Combines matching entries from all lists. | ||
* @param xs n lists | ||
* @param fm map function (vs, k) | ||
* @param ft till function (dones) (some) | ||
* @param vd default value | ||
*/ | ||
export function zip<T, U, V = U>(xs: Lists<T, U>[], fm?: mapFn<T, U[], U[] | V>, ft?: tillFn, vd?: U): Lists<T, U[] | V>; | ||
export {}; | ||
} |
76
index.js
@@ -63,2 +63,11 @@ 'use strict'; | ||
function unionKeys(...xs) { | ||
var a = new Set(); | ||
for (var x of xs) { | ||
for (var [k] of x) | ||
a.add(k); | ||
} | ||
return a; | ||
} | ||
function concat$(x, ...ys) { | ||
@@ -223,2 +232,22 @@ for (var y of ys) { | ||
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 intersection(x, y, fc = null) { | ||
@@ -370,2 +399,15 @@ var fc = fc || id$1; | ||
function zip(xs, fm = null, ft = null, vd) { | ||
var fm = fm || id$1, ft = ft || some; | ||
var ks = unionKeys(...xs), a = new Map(); | ||
for (var k of ks) { | ||
var ds = xs.map(x => !x.has(k)); | ||
if (ft(ds)) | ||
break; | ||
var vs = xs.map(x => !x.has(k) ? vd : x.get(k)); | ||
a.set(k, fm(vs, k, null)); | ||
} | ||
return a; | ||
} | ||
/** | ||
@@ -381,3 +423,3 @@ * Lists cartesian product of lists. | ||
function someIf(x) { | ||
function someIf$1(x) { | ||
for (var v of x) | ||
@@ -388,3 +430,3 @@ if (v) | ||
} | ||
function someTest(x, fn) { | ||
function someTest$1(x, fn) { | ||
var i = -1; | ||
@@ -396,7 +438,7 @@ for (var v of x) | ||
} | ||
function some(x, fn = null) { | ||
function some$2(x, fn = null) { | ||
if (fn) | ||
return someTest(x, fn); | ||
return someTest$1(x, fn); | ||
else | ||
return someIf(x); | ||
return someIf$1(x); | ||
} | ||
@@ -416,3 +458,3 @@ | ||
function some$1$1(x, fn) { | ||
return some(x, fn); | ||
return some$2(x, fn); | ||
} | ||
@@ -425,3 +467,3 @@ | ||
function zip(xs, fm = null, ft = null, vd) { | ||
function zip$1(xs, fm = null, ft = null, vd) { | ||
var fm = fm || id$1$1, ft = ft || some$1$1; | ||
@@ -454,3 +496,3 @@ var X = xs.length, a = []; | ||
var vss = chunk([...values(x)], n, s); | ||
return zip([kss, vss]); | ||
return zip$1([kss, vss]); | ||
} | ||
@@ -466,3 +508,3 @@ | ||
function unionKeys(...xs) { | ||
function unionKeys$1(...xs) { | ||
var a = new Set(); | ||
@@ -478,3 +520,3 @@ for (var x of xs) { | ||
var fc = fc || cmp$1, fm = fm || id$2; | ||
var ks = unionKeys(x, y); | ||
var ks = unionKeys$1(x, y); | ||
for (var k of ks) { | ||
@@ -1769,3 +1811,3 @@ if (!x.has(k)) | ||
function some$2(x, ft = null) { | ||
function some$3(x, ft = null) { | ||
return some$1(entries(x), ft); | ||
@@ -1809,3 +1851,3 @@ } | ||
function unionKeys$1(...xs) { | ||
function unionKeys$2(...xs) { | ||
return extraSet_6(...xs.map(x => keys(x))); | ||
@@ -1818,2 +1860,7 @@ } | ||
function zip$2(xs, fm = null, ft = null, vd) { | ||
var a = zip(xs.map(x => new Map(entries(x))), fm, ft, vd); | ||
return [a.keys(), a.values()]; | ||
} | ||
exports.cartesianProduct = cartesianProduct$1; | ||
@@ -1873,3 +1920,3 @@ exports.chunk = chunk$1; | ||
exports.size = size$1; | ||
exports.some = some$2; | ||
exports.some = some$3; | ||
exports.submap = submap$1; | ||
@@ -1882,4 +1929,5 @@ exports.submaps = submaps$1; | ||
exports.union = union$1; | ||
exports.unionKeys = unionKeys$1; | ||
exports.unionKeys = unionKeys$2; | ||
exports.value = value$1; | ||
exports.values = values; | ||
exports.zip = zip$2; |
{ | ||
"name": "extra-lists", | ||
"version": "2.0.84", | ||
"version": "2.0.85", | ||
"description": "Standard utility methods for Lists.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98444
3744