@thi.ng/transducers
Advanced tools
Comparing version 1.0.7 to 1.1.0
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="1.1.0"></a> | ||
# [1.1.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers@1.0.7...@thi.ng/transducers@1.1.0) (2018-02-08) | ||
### Features | ||
* **transducers:** add page() xform, update readme ([855d803](https://github.com/thi-ng/umbrella/commit/855d803)) | ||
<a name="1.0.7"></a> | ||
@@ -8,0 +19,0 @@ ## [1.0.7](https://github.com/thi-ng/umbrella/compare/@thi.ng/transducers@1.0.6...@thi.ng/transducers@1.0.7) (2018-02-02) |
@@ -17,5 +17,7 @@ "use strict"; | ||
const kx = key(x); | ||
let low = 0, high = arr.length - 1; | ||
let low = 0; | ||
let high = arr.length - 1; | ||
while (low <= high) { | ||
const mid = (low + high) >>> 1, c = cmp(key(arr[mid]), kx); | ||
const mid = (low + high) >>> 1; | ||
const c = cmp(key(arr[mid]), kx); | ||
if (c < 0) { | ||
@@ -22,0 +24,0 @@ low = mid + 1; |
@@ -1,1 +0,1 @@ | ||
export declare function even(x: number): boolean; | ||
export { isEven as even } from "@thi.ng/checks/is-even"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function even(x) { | ||
return (x % 2) === 0; | ||
} | ||
exports.even = even; | ||
var is_even_1 = require("@thi.ng/checks/is-even"); | ||
exports.even = is_even_1.isEven; |
@@ -1,1 +0,1 @@ | ||
export declare function odd(x: number): boolean; | ||
export { isOdd as odd } from "@thi.ng/checks/is-odd"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function odd(x) { | ||
return (x % 2) === 1; | ||
} | ||
exports.odd = odd; | ||
var is_odd_1 = require("@thi.ng/checks/is-odd"); | ||
exports.odd = is_odd_1.isOdd; |
@@ -7,3 +7,5 @@ "use strict"; | ||
while (--n >= 0) { | ||
const a = (Math.random() * l) | 0, b = (Math.random() * l) | 0, t = buf[a]; | ||
const a = (Math.random() * l) | 0; | ||
const b = (Math.random() * l) | 0; | ||
const t = buf[a]; | ||
buf[a] = buf[b]; | ||
@@ -10,0 +12,0 @@ buf[b] = t; |
@@ -15,3 +15,4 @@ "use strict"; | ||
function weightedRandom(choices, weights) { | ||
const n = choices.length, opts = [...tuples_1.tuples(choices, weights || repeat_1.repeat(1))].sort((a, b) => b[1] - a[1]); | ||
const n = choices.length; | ||
const opts = [...tuples_1.tuples(choices, weights || repeat_1.repeat(1))].sort((a, b) => b[1] - a[1]); | ||
let total = 0, i, r, sum; | ||
@@ -18,0 +19,0 @@ for (i = 0; i < n; i++) { |
@@ -60,2 +60,3 @@ export * from "./api"; | ||
export * from "./xform/pad-last"; | ||
export * from "./xform/page"; | ||
export * from "./xform/partition-by"; | ||
@@ -62,0 +63,0 @@ export * from "./xform/partition-of"; |
@@ -65,2 +65,3 @@ "use strict"; | ||
__export(require("./xform/pad-last")); | ||
__export(require("./xform/page")); | ||
__export(require("./xform/partition-by")); | ||
@@ -67,0 +68,0 @@ __export(require("./xform/partition-of")); |
{ | ||
"name": "@thi.ng/transducers", | ||
"version": "1.0.7", | ||
"version": "1.1.0", | ||
"description": "Lightweight transducer implementations for ES6 / TypeScript", | ||
@@ -29,3 +29,3 @@ "main": "./index.js", | ||
"dependencies": { | ||
"@thi.ng/api": "^2.0.1" | ||
"@thi.ng/api": "^2.0.2" | ||
}, | ||
@@ -32,0 +32,0 @@ "keywords": [ |
@@ -131,2 +131,23 @@ # @thi.ng/transducers | ||
### Pagination | ||
```typescript | ||
// extract only items for given page id & page length | ||
[...tx.iterator(tx.page(0, 5), tx.range(12))] | ||
// [ 0, 1, 2, 3, 4 ] | ||
// when composing with other transducers | ||
// it's most efficient to place `page()` early on in the chain | ||
// that way only the page items will be further processed | ||
[...tx.iterator(tx.comp(tx.page(1, 5), tx.map(x => x * 10)), tx.range(12))] | ||
// [ 50, 60, 70, 80, 90 ] | ||
// use `padLast()` to fill up missing values | ||
[...tx.iterator(tx.comp(tx.page(2, 5), tx.padLast(5, "n/a")), tx.range(12))] | ||
// [ 10, 11, 'n/a', 'n/a', 'n/a' ] | ||
[...tx.iterator(tx.page(3, 5), rtx.ange(12))] | ||
// [] | ||
``` | ||
### Multiplexing / parallel transducer application | ||
@@ -133,0 +154,0 @@ |
@@ -24,3 +24,4 @@ "use strict"; | ||
return comp_1.compR(rfn, (acc, _) => { | ||
let t = Date.now(), x = t - prev; | ||
const t = Date.now(); | ||
const x = t - prev; | ||
prev = t; | ||
@@ -27,0 +28,0 @@ return r(acc, x); |
@@ -7,3 +7,4 @@ "use strict"; | ||
return (rfn) => { | ||
const r = rfn[2], flatten = (acc, x) => { | ||
const r = rfn[2]; | ||
const flatten = (acc, x) => { | ||
x = fn(x); | ||
@@ -10,0 +11,0 @@ if (x) { |
@@ -14,3 +14,4 @@ "use strict"; | ||
return ([init, complete, reduce]) => { | ||
let buf = [], skip = 0; | ||
let buf = []; | ||
let skip = 0; | ||
return [ | ||
@@ -17,0 +18,0 @@ init, |
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
140293
218
2975
740
Updated@thi.ng/api@^2.0.2