@thi.ng/transducers
Advanced tools
Comparing version 0.6.1 to 0.7.0
export * from "./api"; | ||
export * from "./comp"; | ||
export * from "./iterator"; | ||
export * from "./reduce"; | ||
export * from "./reduced"; | ||
export * from "./step"; | ||
export * from "./transduce"; | ||
@@ -27,3 +27,2 @@ export * from "./rfn/add"; | ||
export * from "./xform/cat"; | ||
export * from "./xform/chunk-sort"; | ||
export * from "./xform/dedupe"; | ||
@@ -38,2 +37,3 @@ export * from "./xform/delayed"; | ||
export * from "./xform/flatten"; | ||
export * from "./xform/indexed"; | ||
export * from "./xform/inspect"; | ||
@@ -48,2 +48,3 @@ export * from "./xform/interleave"; | ||
export * from "./xform/partition-by"; | ||
export * from "./xform/partition-sort"; | ||
export * from "./xform/partition"; | ||
@@ -59,7 +60,15 @@ export * from "./xform/pluck"; | ||
export * from "./xform/stream-sort"; | ||
export * from "./xform/swizzle"; | ||
export * from "./xform/take-nth"; | ||
export * from "./xform/take-last"; | ||
export * from "./xform/take-while"; | ||
export * from "./xform/take"; | ||
export * from "./xform/throttle"; | ||
export * from "./func/binary-search"; | ||
export * from "./func/comp"; | ||
export * from "./func/delay"; | ||
export * from "./func/identity"; | ||
export * from "./func/juxt"; | ||
export * from "./func/key-selector"; | ||
export * from "./func/renamer"; | ||
export * from "./func/swizzler"; |
13
index.js
@@ -7,6 +7,6 @@ "use strict"; | ||
__export(require("./api")); | ||
__export(require("./comp")); | ||
__export(require("./iterator")); | ||
__export(require("./reduce")); | ||
__export(require("./reduced")); | ||
__export(require("./step")); | ||
__export(require("./transduce")); | ||
@@ -33,3 +33,2 @@ __export(require("./rfn/add")); | ||
__export(require("./xform/cat")); | ||
__export(require("./xform/chunk-sort")); | ||
__export(require("./xform/dedupe")); | ||
@@ -44,2 +43,3 @@ __export(require("./xform/delayed")); | ||
__export(require("./xform/flatten")); | ||
__export(require("./xform/indexed")); | ||
__export(require("./xform/inspect")); | ||
@@ -54,2 +54,3 @@ __export(require("./xform/interleave")); | ||
__export(require("./xform/partition-by")); | ||
__export(require("./xform/partition-sort")); | ||
__export(require("./xform/partition")); | ||
@@ -65,7 +66,15 @@ __export(require("./xform/pluck")); | ||
__export(require("./xform/stream-sort")); | ||
__export(require("./xform/swizzle")); | ||
__export(require("./xform/take-nth")); | ||
__export(require("./xform/take-last")); | ||
__export(require("./xform/take-while")); | ||
__export(require("./xform/take")); | ||
__export(require("./xform/throttle")); | ||
__export(require("./func/binary-search")); | ||
__export(require("./func/comp")); | ||
__export(require("./func/delay")); | ||
__export(require("./func/identity")); | ||
__export(require("./func/juxt")); | ||
__export(require("./func/key-selector")); | ||
__export(require("./func/renamer")); | ||
__export(require("./func/swizzler")); |
{ | ||
"name": "@thi.ng/transducers", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "Lightweight transducer implementations for ES6 / TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,3 +7,3 @@ # @thi.ng/transducers | ||
The library provides 35 transducers and 15 reducers for composing data | ||
The library provides 36 transducers and 18 reducers for composing data | ||
transformation pipelines (more to come). | ||
@@ -296,6 +296,4 @@ | ||
#### `cat<A>(): Transducer<A[], A>` | ||
#### `cat<T>(): Transducer<T[], T>` | ||
#### `chunkSort<T>(n: number, key?: ((x: T) => any), cmp?: Comparator<any>): Transducer<T, T>` | ||
#### `dedupe<T>(equiv?: (a: T, b: T) => boolean): Transducer<T, T>` | ||
@@ -319,2 +317,4 @@ | ||
#### `indexed<T>(): Transducer<T, [number, T]>` | ||
#### `inspect<T>(prefix?: string): Transducer<T, T>` | ||
@@ -338,4 +338,6 @@ | ||
#### `pluck(key: PropertyKey): Transducer<any, any>` | ||
#### `partitionSort<A, B>(n: number, key?: ((x: A) => B), cmp?: Comparator<B>): Transducer<A, A>` | ||
#### `pluck<A, B>(key: PropertyKey): Transducer<A, B>` | ||
#### `repeat<T>(n: number): Transducer<T, T>` | ||
@@ -353,3 +355,3 @@ | ||
#### `streamSort<T>(n: number, key?: ((x: T) => any), cmp?: Comparator<any>): Transducer<T, T>` | ||
#### `streamSort<A, B>(n: number, key?: ((x: A) => B), cmp?: Comparator<B>): Transducer<A, A>` | ||
@@ -378,2 +380,8 @@ #### `take<T>(n: number): Transducer<T, T>` | ||
#### `groupBinary<T>(bits: number, key: (x: T) => number, branch?: () => IObjectOf<T[]>, leaf?: Reducer<any, T>, left?: PropertyKey, right?: PropertyKey): Reducer<any, T>` | ||
#### `groupByMap<A, B, C>(key: (x: A) => B, rfn?: Reducer<C, A>): Reducer<Map<B, C>, A>` | ||
#### `groupByObj<A, C>(key: (x: A) => PropertyKey, rfn?: Reducer<C, A>, init?: () => IObjectOf<C>): Reducer<IObjectOf<C>, A>` | ||
#### `last(): last<T>(): Reducer<T, T>` | ||
@@ -380,0 +388,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
function benchmark() { | ||
@@ -5,0 +5,0 @@ return (rfn) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
const reduced_1 = require("../reduced"); | ||
@@ -5,0 +5,0 @@ function cat() { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const api_1 = require("../api"); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
function dedupe(equiv) { | ||
@@ -6,0 +6,0 @@ return (rfn) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const map_1 = require("./map"); | ||
const delay_1 = require("../func/delay"); | ||
function delayed(t) { | ||
return map_1.map((x) => new Promise((resolve) => setTimeout(() => resolve(x), t))); | ||
return map_1.map((x) => delay_1.delay(x, t)); | ||
} | ||
exports.delayed = delayed; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
const identity_1 = require("../func/identity"); | ||
@@ -5,0 +5,0 @@ function distinct(mapfn = identity_1.identity) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
function dropNth(n) { | ||
@@ -5,0 +5,0 @@ n--; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
function dropWhile(pred) { | ||
@@ -5,0 +5,0 @@ return (rfn) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
function drop(n) { | ||
@@ -5,0 +5,0 @@ return (rfn) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
function filter(pred) { | ||
@@ -5,0 +5,0 @@ return (rfn) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
const reduced_1 = require("../reduced"); | ||
@@ -5,0 +5,0 @@ function flattenWith(fn) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
const reduced_1 = require("../reduced"); | ||
@@ -5,0 +5,0 @@ function interleave(sep) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
const reduced_1 = require("../reduced"); | ||
@@ -5,0 +5,0 @@ function interpose(sep) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
const identity_1 = require("../func/identity"); | ||
@@ -5,0 +5,0 @@ function keep(f = identity_1.identity) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
function mapIndexed(fn) { | ||
@@ -5,0 +5,0 @@ return (rfn) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
function map(fn) { | ||
@@ -5,0 +5,0 @@ return (rfn) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
const cat_1 = require("./cat"); | ||
@@ -5,0 +5,0 @@ const map_1 = require("./map"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
const reduce_1 = require("../reduce"); | ||
@@ -8,5 +8,6 @@ const mean_1 = require("../rfn/mean"); | ||
const partition_1 = require("./partition"); | ||
// TODO optimize | ||
function movingAverage(n) { | ||
return comp_1.comp(partition_1.partition(n, 1), map_1.map((x) => reduce_1.reduce(mean_1.mean(), x))); | ||
return comp_1.comp(partition_1.partition(n, 1, true), map_1.map((x) => reduce_1.reduce(mean_1.mean(), x))); | ||
} | ||
exports.movingAverage = movingAverage; |
@@ -5,7 +5,6 @@ "use strict"; | ||
function partitionBy(fn) { | ||
return (rfn) => { | ||
const r = rfn[2]; | ||
return ([i, c, r]) => { | ||
let prev = {}, chunk; | ||
return [ | ||
() => rfn[0](), | ||
() => i(), | ||
(acc) => { | ||
@@ -16,3 +15,3 @@ if (chunk && chunk.length) { | ||
} | ||
return rfn[1](acc); | ||
return c(acc); | ||
}, | ||
@@ -19,0 +18,0 @@ (acc, x) => { |
@@ -13,7 +13,6 @@ "use strict"; | ||
} | ||
return (rfn) => { | ||
const r = rfn[2]; | ||
return ([i, c, r]) => { | ||
let buf = [], skip = 0; | ||
return [ | ||
() => rfn[0](), | ||
() => i(), | ||
(acc) => { | ||
@@ -24,3 +23,3 @@ if (buf.length && (all || buf.length === size)) { | ||
} | ||
return rfn[1](acc); | ||
return c(acc); | ||
}, | ||
@@ -27,0 +26,0 @@ (acc, x) => { |
import { Transducer } from "../api"; | ||
export declare function pluck(key: PropertyKey): Transducer<any, any>; | ||
export declare function pluck<A, B>(key: PropertyKey): Transducer<A, B>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
const transduce_1 = require("../transduce"); | ||
const renamer_1 = require("../func/renamer"); | ||
const filter_1 = require("./filter"); | ||
const map_1 = require("./map"); | ||
function rename(kmap, rfn) { | ||
const ks = Object.keys(kmap); | ||
if (rfn) { | ||
const ks = Object.keys(kmap); | ||
return map_1.map((y) => transduce_1.transduce(comp_1.comp(map_1.map((k) => [k, y[kmap[k]]]), filter_1.filter(x => x[1] !== undefined)), rfn, ks)); | ||
} | ||
else { | ||
return map_1.map((y) => { | ||
const res = {}; | ||
for (let i = ks.length - 1; i >= 0; i--) { | ||
const k = ks[i], v = y[kmap[k]]; | ||
v !== undefined && (res[k] = v); | ||
} | ||
return res; | ||
}); | ||
return map_1.map(renamer_1.renamer(kmap)); | ||
} | ||
} | ||
exports.rename = rename; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
const reduced_1 = require("../reduced"); | ||
@@ -5,0 +5,0 @@ function repeat(n) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
function sample(prob) { | ||
@@ -5,0 +5,0 @@ return (rfn) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
const reduced_1 = require("../reduced"); | ||
@@ -5,0 +5,0 @@ function scan(inner, acc) { |
import { Transducer } from "../api"; | ||
export declare function selectKeys(keys: PropertyKey[]): Transducer<any, any>; | ||
export declare function selectKeys<T>(keys: PropertyKey[]): Transducer<T, any>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const map_1 = require("./map"); | ||
const key_selector_1 = require("../func/key-selector"); | ||
function selectKeys(keys) { | ||
const [a, b, c] = keys; | ||
switch (keys.length) { | ||
case 0: | ||
throw new Error("no keys given"); | ||
case 1: | ||
return map_1.map((x) => x.hasOwnProperty(a) ? { [a]: x[a] } : {}); | ||
case 2: | ||
return map_1.map((x) => { | ||
const res = {}; | ||
x.hasOwnProperty(a) && (res[a] = x[a]); | ||
x.hasOwnProperty(b) && (res[b] = x[b]); | ||
return res; | ||
}); | ||
case 3: | ||
return map_1.map((x) => { | ||
const res = {}; | ||
x.hasOwnProperty(a) && (res[a] = x[a]); | ||
x.hasOwnProperty(b) && (res[b] = x[b]); | ||
x.hasOwnProperty(c) && (res[c] = x[c]); | ||
return res; | ||
}); | ||
default: | ||
return map_1.map((x) => { | ||
const res = {}; | ||
for (let i = keys.length - 1; i >= 0; i--) { | ||
const k = keys[i]; | ||
x.hasOwnProperty(k) && (res[k] = x[k]); | ||
} | ||
return res; | ||
}); | ||
} | ||
return map_1.map(key_selector_1.keySelector(keys)); | ||
} | ||
exports.selectKeys = selectKeys; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const reduced_1 = require("../reduced"); | ||
function shuffle(buf, n) { | ||
const l = buf.length; | ||
n = n < l ? n : l; | ||
while (--n >= 0) { | ||
const a = (Math.random() * l) | 0, b = (Math.random() * l) | 0, t = buf[a]; | ||
buf[a] = buf[b]; | ||
buf[b] = t; | ||
} | ||
} | ||
const shuffle_1 = require("../func/shuffle"); | ||
function streamShuffle(n, maxSwaps = n) { | ||
@@ -20,3 +12,3 @@ return ([i, c, r]) => { | ||
while (buf.length && !reduced_1.isReduced(acc)) { | ||
shuffle(buf, maxSwaps); | ||
shuffle_1.shuffleN(buf, maxSwaps); | ||
acc = r(acc, buf.shift()); | ||
@@ -29,3 +21,3 @@ } | ||
buf.push(x); | ||
shuffle(buf, maxSwaps); | ||
shuffle_1.shuffleN(buf, maxSwaps); | ||
if (buf.length === n) { | ||
@@ -32,0 +24,0 @@ acc = r(acc, buf.shift()); |
import { Comparator } from "@thi.ng/api/api"; | ||
import { Transducer } from "../api"; | ||
export declare function streamSort<T>(n: number, key?: ((x: T) => any), cmp?: Comparator<any>): Transducer<T, T>; | ||
export declare function streamSort<A, B>(n: number, key?: ((x: A) => B), cmp?: Comparator<B>): Transducer<A, A>; |
@@ -6,19 +6,3 @@ "use strict"; | ||
const identity_1 = require("../func/identity"); | ||
function binarySearch(arr, key, cmp, x) { | ||
const kx = key(x); | ||
let low = 0, high = arr.length - 1; | ||
while (low <= high) { | ||
const mid = (low + high) >>> 1, c = cmp(key(arr[mid]), kx); | ||
if (c < 0) { | ||
low = mid + 1; | ||
} | ||
else if (c > 0) { | ||
high = mid - 1; | ||
} | ||
else { | ||
return mid; | ||
} | ||
} | ||
return low; | ||
} | ||
const binary_search_1 = require("../func/binary-search"); | ||
function streamSort(n, key = identity_1.identity, cmp = compare_1.compare) { | ||
@@ -33,7 +17,7 @@ return ([i, c, r]) => { | ||
} | ||
acc = c(acc); | ||
return acc; | ||
return c(acc); | ||
}, | ||
(acc, x) => { | ||
buf.splice(binarySearch(buf, key, cmp, x), 0, x); | ||
const idx = binary_search_1.binarySearch(buf, key, cmp, x); | ||
buf.splice((idx < 0 ? -(idx + 1) : idx), 0, x); | ||
if (buf.length === n) { | ||
@@ -40,0 +24,0 @@ acc = r(acc, buf.shift()); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
function takeNth(n) { | ||
@@ -5,0 +5,0 @@ n--; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
const reduced_1 = require("../reduced"); | ||
@@ -5,0 +5,0 @@ function takeWhile(pred) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
const reduced_1 = require("../reduced"); | ||
@@ -5,0 +5,0 @@ function take(n) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../comp"); | ||
const comp_1 = require("../func/comp"); | ||
function throttle(delay) { | ||
@@ -5,0 +5,0 @@ return (rfn) => { |
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
67141
146
1615
401