@thi.ng/transducers
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -17,3 +17,13 @@ import { Comparator, IDeref, Predicate } from "@thi.ng/api"; | ||
export declare function unreduced(x: any): any; | ||
export declare function comp(...fns: ((x: any) => any)[]): (x: any) => any; | ||
export declare function comp<A, B>(a: Transducer<A, B>): Transducer<A, B>; | ||
export declare function comp<A, B, C>(a: Transducer<A, B>, b: Transducer<B, C>): Transducer<A, C>; | ||
export declare function comp<A, B, C, D>(a: Transducer<A, B>, b: Transducer<B, C>, c: Transducer<C, D>): Transducer<A, D>; | ||
export declare function comp<A, B, C, D, E>(a: Transducer<A, B>, b: Transducer<B, C>, c: Transducer<C, D>, d: Transducer<D, E>): Transducer<A, E>; | ||
export declare function comp<A, B, C, D, E, F>(a: Transducer<A, B>, b: Transducer<B, C>, c: Transducer<C, D>, d: Transducer<D, E>, e: Transducer<E, F>): Transducer<A, F>; | ||
export declare function comp<A, B, C, D, E, F, G>(a: Transducer<A, B>, b: Transducer<B, C>, c: Transducer<C, D>, d: Transducer<D, E>, e: Transducer<E, F>, f: Transducer<F, G>): Transducer<A, G>; | ||
export declare function comp<A, B, C, D, E, F, G, H>(a: Transducer<A, B>, b: Transducer<B, C>, c: Transducer<C, D>, d: Transducer<D, E>, e: Transducer<E, F>, f: Transducer<F, G>, g: Transducer<G, H>): Transducer<A, H>; | ||
export declare function comp<A, B, C, D, E, F, G, H, I>(a: Transducer<A, B>, b: Transducer<B, C>, c: Transducer<C, D>, d: Transducer<D, E>, e: Transducer<E, F>, f: Transducer<F, G>, g: Transducer<G, H>, h: Transducer<H, I>): Transducer<A, I>; | ||
export declare function comp<A, B, C, D, E, F, G, H, I, J>(a: Transducer<A, B>, b: Transducer<B, C>, c: Transducer<C, D>, d: Transducer<D, E>, e: Transducer<E, F>, f: Transducer<F, G>, g: Transducer<G, H>, h: Transducer<H, I>, i: Transducer<I, J>): Transducer<A, J>; | ||
export declare function comp<A, B, C, D, E, F, G, H, I, J, K>(a: Transducer<A, B>, b: Transducer<B, C>, c: Transducer<C, D>, d: Transducer<D, E>, e: Transducer<E, F>, f: Transducer<F, G>, g: Transducer<G, H>, h: Transducer<H, I>, i: Transducer<I, J>, j: Transducer<J, K>): Transducer<A, K>; | ||
export declare function comp<A, B, C, D, E, F, G, H, I, J, K>(a: Transducer<A, B>, b: Transducer<B, C>, c: Transducer<C, D>, d: Transducer<D, E>, e: Transducer<E, F>, f: Transducer<F, G>, g: Transducer<G, H>, h: Transducer<H, I>, i: Transducer<I, J>, j: Transducer<J, K>, ...fns: Transducer<any, any>[]): Transducer<A, any>; | ||
export declare function compR(rfn: Reducer<any, any>, fn: (acc, x) => any): Reducer<any, any>; | ||
@@ -28,3 +38,4 @@ export declare function identity<T>(x: T): T; | ||
export declare function map<A, B>(fn: (x: A) => B): Transducer<A, B>; | ||
export declare function selectKeys(...keys: PropertyKey[]): Transducer<any, any>; | ||
export declare function pluck(key: PropertyKey): Transducer<any, any>; | ||
export declare function selectKeys(keys: PropertyKey[]): Transducer<any, any>; | ||
export declare function mapIndexed<A, B>(fn: (i: number, x: A) => B): Transducer<A, B>; | ||
@@ -37,2 +48,3 @@ export declare function mapcat<A, B>(fn: (x: A) => Iterable<B>): Transducer<A, B>; | ||
export declare function filter<T>(pred: Predicate<T>): Transducer<T, T>; | ||
export declare function keep<T>(f?: ((x: T) => any)): Transducer<T, T>; | ||
export declare function throttle<T>(delay: number): Transducer<T, T>; | ||
@@ -39,0 +51,0 @@ export declare function delayed<T>(t: number): Transducer<T, Promise<T>>; |
34
index.js
@@ -143,13 +143,28 @@ "use strict"; | ||
exports.map = map; | ||
function selectKeys(...keys) { | ||
function pluck(key) { | ||
return map((x) => x[key]); | ||
} | ||
exports.pluck = pluck; | ||
function selectKeys(keys) { | ||
const [a, b, c] = keys; | ||
switch (keys.length) { | ||
case 0: | ||
throw new Error(`no keys given`); | ||
throw new Error("no keys given"); | ||
case 1: | ||
return map((x) => x[a]); | ||
return map((x) => x.hasOwnProperty(a) ? { [a]: x[a] } : {}); | ||
case 2: | ||
return map((x) => ({ [a]: x[a], [b]: x[b] })); | ||
return map((x) => { | ||
const res = {}; | ||
x.hasOwnProperty(a) && (res[a] = x[a]); | ||
x.hasOwnProperty(b) && (res[b] = x[b]); | ||
return res; | ||
}); | ||
case 3: | ||
return map((x) => ({ [a]: x[a], [b]: x[b], [c]: x[c] })); | ||
return 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: | ||
@@ -160,3 +175,3 @@ return map((x) => { | ||
const k = keys[i]; | ||
res[k] = x[k]; | ||
x.hasOwnProperty(k) && (res[k] = x[k]); | ||
} | ||
@@ -240,2 +255,9 @@ return res; | ||
exports.filter = filter; | ||
function keep(f = identity) { | ||
return (rfn) => { | ||
const r = rfn[2]; | ||
return compR(rfn, (acc, x) => f(x) != null ? r(acc, x) : acc); | ||
}; | ||
} | ||
exports.keep = keep; | ||
function throttle(delay) { | ||
@@ -242,0 +264,0 @@ return (rfn) => { |
{ | ||
"name": "@thi.ng/transducers", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "Lightweight transducer implementations for ES6 / TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,3 +7,3 @@ # @thi.ng/transducers | ||
The library provides 31 transducers and 14 reducers for composing data | ||
The library provides 33 transducers and 14 reducers for composing data | ||
transformation pipelines (more to come). | ||
@@ -257,2 +257,4 @@ | ||
#### `pluck(key: PropertyKey): Transducer<any, any>` | ||
#### `scan<A, B>(rfn: Reducer<B, A>, acc?: B): Transducer<A, B>` | ||
@@ -262,2 +264,4 @@ | ||
#### `keep<T>(f?: ((x: T) => any)): Transducer<T, T>` | ||
#### `throttle<T>(delay: number): Transducer<T, T>` | ||
@@ -264,0 +268,0 @@ |
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
33462
740
338