Package Exports
- @thi.ng/transducers
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@thi.ng/transducers) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@thi.ng/transducers
Lightweight transducer implementations for ES6 / TypeScript (6KB minified).
Installation
yarn add @thi.ng/transducers
yarn run buildUsage
import * as tx from "@thi.ng/transducers";
xform = tx.comp(
tx.filter(x => (x & 1) > 0), // odd numbers only
tx.distinct(), // distinct numbers only
tx.map(x=> x * 3) // times 3
);
tx.transduce(xform, tx.push, [1, 2, 3, 4, 5, 4, 3, 2, 1]);
// [ 3, 9, 15 ]
tx.transduce(xform, tx.conj, [1, 2, 3, 4, 5, 4, 3, 2, 1]);
// Set { 3, 9, 15 }
tx.transduce(tx.map(x => x.toUpperCase()), tx.frequencies, "hello world")
// Map { 'H' => 1, 'E' => 1, 'L' => 3, 'O' => 2, ' ' => 1, 'W' => 1, 'R' => 1, 'D' => 1 }
tx.reduce(tx.frequencies, "hello world")
// Map { 'h' => 1, 'e' => 1, 'l' => 3, 'o' => 2, ' ' => 1, 'w' => 1, 'r' => 1, 'd' => 1 }
for(let x of tx.iterator(xform, [1, 2, 3, 4])) {
console.log(x);
}
f = tx.step(tx.dedupe());
f(1); // 1
f(2); // 2
f(2); // undefined
f(3); // 3
f(3); // undefined
f(3); // undefined
f(1); // 1API
TODO
reduce<A, B>(rfn: Reducer<A, B>, acc: A, xs: Iterable<B>): A
transduce<A, B, C>(tx: Transducer<A, B>, rfn: Reducer<C, B>, acc: C, xs: Iterable<A>): C
iterator<A, B>(tx: Transducer<A, B>, xs: Iterable<A>): IterableIterator<B>
reduced(x: any): any
isReduced(x: any): boolean
ensureReduced(x: any): Reduced<any>
unreduced(x: any): any
comp(f1, f2, ...)
compR(rfn: Reducer<any, any>, fn: (acc, x) => any): Reducer<any, any>
Transducers
map<A, B>(fn: (x: A) => B): Transducer<A, B>
mapIndexed<A, B>(fn: (i: number, x: A) => B): Transducer<A, B>
mapcat<A, B>(fn: (x: A) => Iterable<B>): Transducer<A, B>
filter<T>(pred: Predicate<T>): Transducer<T, T>
throttle<T>(delay: number): Transducer<T, T>
delayed<T>(t: number): Transducer<T, Promise<T>>
distinct<T>(mapfn?: (x: T) => any): Transducer<T, T>
dedupe<T>(equiv?: (a: T, b: T) => boolean): Transducer<T, T>
interpose<A, B>(sep: B | (() => B)): Transducer<A, A | B>
interleave<A, B>(sep: B | (() => B)): Transducer<A, A | B>
take<T>(n: number): Transducer<T, T>
takeWhile<T>(pred: Predicate<T>): Transducer<T, T>
takeNth<T>(n: number): Transducer<T, T>
drop<T>(n: number): Transducer<T, T>
dropWhile<T>(pred: Predicate<T>): Transducer<T, T>
dropNth<T>(n: number): Transducer<T, T>
repeat<T>(n: number): Transducer<T, T>
sample<T>(prob: number): Transducer<T, T>
partition<T>(size: number, step?: number, all?: boolean): Transducer<T, T[]>
partitionBy<T>(fn: (x: T) => any): Transducer<T, T[]>
chunkSort<T>(n: number, key?: (x) => any): Transducer<T, T>
streamSort<T>(n: number, key?: (x) => any): Transducer<T, T>
Reducers
push: Reducer<any[], any>
conj: Reducer<Set<any>, any>
assocObj: Reducer<any, [PropertyKey, any]>
assocMap: Reducer<Map<any, any>, [any, any]>
add: Reducer<number, number>
mul: Reducer<number, number>
frequencies: Reducer<Map<any, number>, any
Authors
- Karsten Schmidt
License
© 2016-2018 Karsten Schmidt // Apache Software License 2.0