Skip to content

Commit

Permalink
feat(transducers): update re-exports, extract throttleTime() into own…
Browse files Browse the repository at this point in the history
… file
  • Loading branch information
postspectacular committed Jan 27, 2018
1 parent 8e5204d commit 45d6bc6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
5 changes: 5 additions & 0 deletions packages/transducers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from "./rfn/assoc-map";
export * from "./rfn/assoc-obj";
export * from "./rfn/conj";
export * from "./rfn/count";
export * from "./rfn/every";
export * from "./rfn/frequencies";
export * from "./rfn/group-binary";
export * from "./rfn/group-by-map";
Expand All @@ -24,6 +25,7 @@ export * from "./rfn/mul";
export * from "./rfn/push-copy";
export * from "./rfn/push";
export * from "./rfn/reductions";
export * from "./rfn/some";
export * from "./rfn/str";

export * from "./xform/base64";
Expand All @@ -46,13 +48,15 @@ export * from "./xform/inspect";
export * from "./xform/interleave";
export * from "./xform/interpose";
export * from "./xform/keep";
export * from "./xform/labeled";
export * from "./xform/map-indexed";
export * from "./xform/map-keys";
export * from "./xform/map-nth";
export * from "./xform/map";
export * from "./xform/mapcat";
export * from "./xform/moving-average";
export * from "./xform/multiplex";
export * from "./xform/multiplex-obj";
export * from "./xform/pad-last";
export * from "./xform/partition-by";
export * from "./xform/partition-of";
Expand All @@ -73,6 +77,7 @@ export * from "./xform/take-last";
export * from "./xform/take-while";
export * from "./xform/take";
export * from "./xform/throttle";
export * from "./xform/throttle-time";
export * from "./xform/utf8";

export * from "./func/binary-search";
Expand Down
23 changes: 23 additions & 0 deletions packages/transducers/src/xform/throttle-time.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Transducer } from "../api";
import { throttle } from "./throttle";

/**
* Time-based version of `throttle`. Ignores any new values in the
* `delay` interval since the last accepted value.
*
* **Only to be used in async contexts and NOT with `transduce` directly.**
*
* Also see: `@thi.ng/rstream` and `@thi.ng/csp` packages.
*
* @param delay
*/
export function throttleTime<T>(delay: number): Transducer<T, T> {
return throttle<T>(
() => {
let last = 0;
return () => {
const t = Date.now();
return t - last >= delay ? (last = t, true) : false;
};
});
}
21 changes: 0 additions & 21 deletions packages/transducers/src/xform/throttle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,3 @@ export function throttle<T>(pred: () => Predicate<T>): Transducer<T, T> {
(acc, x) => _pred(x) ? r(acc, x) : acc);
};
}

/**
* Time-based version of `throttle`. Ignores any new values in the
* `delay` interval since the last accepted value.
*
* **Only to be used in async contexts and NOT with `transduce` directly.**
*
* Also see: `@thi.ng/rstream` and `@thi.ng/csp` packages.
*
* @param delay
*/
export function throttleTime<T>(delay: number): Transducer<T, T> {
return throttle<T>(
() => {
let last = 0;
return () => {
const t = Date.now();
return t - last >= delay ? (last = t, true) : false;
};
});
}

0 comments on commit 45d6bc6

Please sign in to comment.