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
337
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 1.12.0 to 1.12.1

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

<a name="1.12.1"></a>
## [1.12.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers@1.12.0...@thi.ng/transducers@1.12.1) (2018-07-09)
**Note:** Version bump only for package @thi.ng/transducers
<a name="1.12.0"></a>

@@ -8,0 +16,0 @@ # [1.12.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers@1.11.1...@thi.ng/transducers@1.12.0) (2018-07-03)

2

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

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

import { Reducer } from "./api";
import { Reduced } from "./reduced";
export declare function reduce<A, B>(rfn: Reducer<A, B>, xs: Iterable<B>): A;
export declare function reduce<A, B>(rfn: Reducer<A, B>, acc: A, xs: Iterable<B>): A;
/**
* Convenience helper for building a full `Reducer` using the identity
* function (i.e. `(x) => x`) as completion step (true for 90% of all
* bundled transducers).
*
* @param init init step of reducer
* @param rfn reduction step of reducer
*/
export declare function reducer<A, B>(init: () => A, rfn: (acc: A, x: B) => A | Reduced<A>): Reducer<A, B>;

@@ -30,1 +30,13 @@ "use strict";

exports.reduce = reduce;
/**
* Convenience helper for building a full `Reducer` using the identity
* function (i.e. `(x) => x`) as completion step (true for 90% of all
* bundled transducers).
*
* @param init init step of reducer
* @param rfn reduction step of reducer
*/
function reducer(init, rfn) {
return [init, (acc) => acc, rfn];
}
exports.reducer = reducer;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
function add() {
return [
() => 0,
(acc) => acc,
(acc, x) => acc + x,
];
return reduce_1.reducer(() => 0, (acc, x) => acc + x);
}
exports.add = add;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
function assocMap() {
return [
() => new Map(),
(acc) => acc,
(acc, [k, v]) => acc.set(k, v),
];
return reduce_1.reducer(() => new Map(), (acc, [k, v]) => acc.set(k, v));
}
exports.assocMap = assocMap;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
function assocObj() {
return [
() => new Object(),
(acc) => acc,
(acc, [k, v]) => (acc[k] = v, acc),
];
return reduce_1.reducer(() => new Object(), (acc, [k, v]) => (acc[k] = v, acc));
}
exports.assocObj = assocObj;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
function conj() {
return [
() => new Set(),
(acc) => acc,
(acc, x) => acc.add(x),
];
return reduce_1.reducer(() => new Set(), (acc, x) => acc.add(x));
}
exports.conj = conj;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
function count(offset = 0, step = 1) {
return [
() => offset,
(acc) => acc,
(acc, _) => acc + step,
];
return reduce_1.reducer(() => offset, (acc, _) => acc + step);
}
exports.count = count;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
const reduced_1 = require("../reduced");
function every(pred) {
return [
() => true,
(acc) => acc,
pred ?
(acc, x) => (pred(x) ? acc : reduced_1.reduced(false)) :
(acc, x) => (x ? acc : reduced_1.reduced(false))
];
return reduce_1.reducer(() => true, pred ?
(acc, x) => (pred(x) ? acc : reduced_1.reduced(false)) :
(acc, x) => (x ? acc : reduced_1.reduced(false)));
}
exports.every = every;

@@ -5,14 +5,11 @@ "use strict";

const push_1 = require("./push");
const reduce_1 = require("../reduce");
function groupByMap(key = identity_1.identity, rfn = push_1.push()) {
return [
() => new Map(),
(acc) => acc,
(acc, x) => {
const k = key(x);
return acc.set(k, acc.has(k) ?
rfn[2](acc.get(k), x) :
rfn[2](rfn[0](), x));
}
];
return reduce_1.reducer(() => new Map(), (acc, x) => {
const k = key(x);
return acc.set(k, acc.has(k) ?
rfn[2](acc.get(k), x) :
rfn[2](rfn[0](), x));
});
}
exports.groupByMap = groupByMap;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
const push_1 = require("./push");
function groupByObj(key, rfn = push_1.push(), init) {
return [
init || (() => new Object()),
(acc) => acc,
(acc, x) => {
const k = key(x);
acc[k] = acc[k] ?
rfn[2](acc[k], x) :
rfn[2](rfn[0](), x);
return acc;
}
];
return reduce_1.reducer(init || (() => new Object()), (acc, x) => {
const k = key(x);
acc[k] = acc[k] ?
rfn[2](acc[k], x) :
rfn[2](rfn[0](), x);
return acc;
});
}
exports.groupByObj = groupByObj;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
function last() {
return [
() => undefined,
(acc) => acc,
(_, x) => x,
];
return reduce_1.reducer(() => undefined, (_, x) => x);
}
exports.last = last;
import { Comparator } from "@thi.ng/api/api";
import { Reducer } from "../api";
export declare function maxCompare<T>(ident: () => T, cmp?: Comparator<T>): Reducer<T, T>;
export declare function maxCompare<T>(init: () => T, cmp?: Comparator<T>): Reducer<T, T>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const compare_1 = require("@thi.ng/compare");
function maxCompare(ident, cmp = compare_1.compare) {
return [
ident,
(acc) => acc,
(acc, x) => cmp(acc, x) >= 0 ? acc : x
];
const reduce_1 = require("../reduce");
function maxCompare(init, cmp = compare_1.compare) {
return reduce_1.reducer(init, (acc, x) => cmp(acc, x) >= 0 ? acc : x);
}
exports.maxCompare = maxCompare;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
function max() {
return [
() => Number.NEGATIVE_INFINITY,
(acc) => acc,
(acc, x) => Math.max(acc, x),
];
return reduce_1.reducer(() => Number.NEGATIVE_INFINITY, (acc, x) => Math.max(acc, x));
}
exports.max = max;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
function mean() {
let n = 0;
return [
() => 0,
(acc) => acc / n,
(acc, x) => (n++, acc + x),
];
return reduce_1.reducer(() => 0, (acc, x) => (n++, acc + x));
}
exports.mean = mean;
import { Comparator } from "@thi.ng/api/api";
import { Reducer } from "../api";
export declare function minCompare<T>(ident: () => T, cmp?: Comparator<T>): Reducer<T, T>;
export declare function minCompare<T>(init: () => T, cmp?: Comparator<T>): Reducer<T, T>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const compare_1 = require("@thi.ng/compare");
function minCompare(ident, cmp = compare_1.compare) {
return [
ident,
(acc) => acc,
(acc, x) => cmp(acc, x) <= 0 ? acc : x
];
const reduce_1 = require("../reduce");
function minCompare(init, cmp = compare_1.compare) {
return reduce_1.reducer(init, (acc, x) => cmp(acc, x) <= 0 ? acc : x);
}
exports.minCompare = minCompare;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
function min() {
return [
() => Number.POSITIVE_INFINITY,
(acc) => acc,
(acc, x) => Math.min(acc, x),
];
return reduce_1.reducer(() => Number.POSITIVE_INFINITY, (acc, x) => Math.min(acc, x));
}
exports.min = min;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
function mul() {
return [
() => 1,
(acc) => acc,
(acc, x) => acc * x,
];
return reduce_1.reducer(() => 1, (acc, x) => acc * x);
}
exports.mul = mul;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
function pushCopy() {
return [
() => [],
(acc) => acc,
(acc, x) => ((acc = acc.slice()).push(x), acc)
];
return reduce_1.reducer(() => [], (acc, x) => ((acc = acc.slice()).push(x), acc));
}
exports.pushCopy = pushCopy;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
function push() {
return [
() => [],
(acc) => acc,
(acc, x) => (acc.push(x), acc),
];
return reduce_1.reducer(() => [], (acc, x) => (acc.push(x), acc));
}
exports.push = push;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reduce_1 = require("../reduce");
const reduced_1 = require("../reduced");
function some(pred) {
return [
() => false,
(acc) => acc,
pred ?
(acc, x) => (pred(x) ? reduced_1.reduced(true) : acc) :
(acc, x) => (x ? reduced_1.reduced(true) : acc)
];
return reduce_1.reducer(() => false, pred ?
(acc, x) => (pred(x) ? reduced_1.reduced(true) : acc) :
(acc, x) => (x ? reduced_1.reduced(true) : acc));
}
exports.some = some;
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