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

@thi.ng/transducers

Package Overview
Dependencies
Maintainers
1
Versions
331
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/transducers - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

6

index.d.ts

@@ -64,3 +64,6 @@ import { Comparator, IDeref, Predicate } from "@thi.ng/api";

export declare function sample<T>(prob: number): Transducer<T, T>;
export declare function partition<T>(size: number, step?: number, all?: boolean): Transducer<T, T[]>;
export declare function partition<T>(size: number): Transducer<T, T[]>;
export declare function partition<T>(size: number, all: boolean): Transducer<T, T[]>;
export declare function partition<T>(size: number, step: number): Transducer<T, T[]>;
export declare function partition<T>(size: number, step: number, all: boolean): Transducer<T, T[]>;
export declare function partitionBy<T>(fn: (x: T) => any): Transducer<T, T[]>;

@@ -78,2 +81,3 @@ export declare function chunkSort<T>(n: number, key?: ((x: T) => any), cmp?: Comparator<any>): Transducer<T, T>;

export declare const mul: Reducer<number, number>;
export declare function mean(): Reducer<number, number>;
export declare const min: Reducer<number, number>;

@@ -80,0 +84,0 @@ export declare const max: Reducer<number, number>;

@@ -93,3 +93,3 @@ "use strict";

}
const [i, _, r] = args[0];
const [i, c, r] = args[0];
acc = acc == null ? i() : acc;

@@ -99,6 +99,7 @@ for (let x of xs) {

if (isReduced(acc)) {
return acc.deref();
acc = acc.deref();
break;
}
}
return acc;
return unreduced(c(acc));
}

@@ -120,3 +121,3 @@ exports.reduce = reduce;

const _rfn = args[0](args[1]);
return unreduced(_rfn[1](reduce(_rfn, acc, xs)));
return reduce(_rfn, acc, xs);
}

@@ -445,3 +446,12 @@ exports.transduce = transduce;

exports.sample = sample;
function partition(size, step = size, all = false) {
function partition(...args) {
let size = args[0], all, step;
if (typeof args[1] == "number") {
step = args[1];
all = args[2];
}
else {
step = size;
all = args[1];
}
return (rfn) => {

@@ -626,2 +636,11 @@ const r = rfn[2];

];
function mean() {
let n = 0;
return [
() => 0,
(acc) => acc / n,
(acc, x) => (n++, acc + x),
];
}
exports.mean = mean;
exports.min = [

@@ -628,0 +647,0 @@ () => Number.POSITIVE_INFINITY,

2

package.json
{
"name": "@thi.ng/transducers",
"version": "0.5.1",
"version": "0.5.2",
"description": "Lightweight transducer implementations for ES6 / TypeScript",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -7,3 +7,3 @@ # @thi.ng/transducers

The library provides 33 transducers and 14 reducers for composing data
The library provides 33 transducers and 15 reducers for composing data
transformation pipelines (more to come).

@@ -48,2 +48,14 @@

// moving average using sliding window
// use nested reduce to compute window averages
tx.transduce(
tx.comp(
tx.partition(5, 1),
tx.map(x => tx.reduce(tx.mean(), x))
),
tx.push,
[1, 2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10]
);
// [ 2.6, 3.4, 4, 4.6, 5.4, 6.2, 6.8, 7.6, 8.4 ]
// apply inspectors to debug transducer pipeline

@@ -332,2 +344,4 @@ // alternatively, use tx.sideEffect() for any side fx

#### `mean(): Reducer<number, number>`
#### `frequencies: Reducer<Map<any, number>, any`

@@ -334,0 +348,0 @@

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