Skip to content

Commit

Permalink
refactor(transducers): restructure, migrate / remove various functions
Browse files Browse the repository at this point in the history
BREAKING CHANGE: migrate / remove various functions to other packages

- constantly(), delay(), identity() => @thi.ng/compose
- randomID(), weightedRandom() => @thi.ng/random
- remove re-exports:
  - even(), odd() (from @thi.ng/checks)
  - juxt() (from @thi.ng/compose)
- remove obsolete hex() fn (use @thi.ng/strings fns instead)
  • Loading branch information
postspectacular committed Feb 12, 2019
1 parent dd13fa9 commit 05bf213
Show file tree
Hide file tree
Showing 20 changed files with 16 additions and 47 deletions.
2 changes: 0 additions & 2 deletions packages/transducers/src/func/constantly.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/transducers/src/func/delay.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/transducers/src/func/even.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/transducers/src/func/hex.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/transducers/src/func/identity.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/transducers/src/func/juxt.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/transducers/src/func/odd.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/transducers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,11 @@ export * from "./xform/word-wrap";

export * from "./func/comp";
export * from "./func/compr";
export * from "./func/constantly";
export * from "./func/deep-transform";
export * from "./func/delay";
export * from "./func/even";
export * from "./func/hex";
export * from "./func/identity";
export * from "./func/juxt";
export * from "./func/juxtr";
export * from "./func/key-selector";
export * from "./func/lookup";
export * from "./func/odd";
export * from "./func/random-id";
export * from "./func/renamer";
export * from "./func/weighted-random";

export * from "./iter/as-iterable";
export * from "./iter/choices";
Expand Down
2 changes: 1 addition & 1 deletion packages/transducers/src/rfn/frequencies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fn } from "@thi.ng/api";
import { identity } from "@thi.ng/compose";
import { Reducer } from "../api";
import { identity } from "../func/identity";
import { $$reduce } from "../reduce";
import { count } from "./count";
import { groupByMap } from "./group-by-map";
Expand Down
4 changes: 2 additions & 2 deletions packages/transducers/src/rfn/group-by-map.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Reducer, GroupByOpts } from "../api";
import { identity } from "../func/identity";
import { identity } from "@thi.ng/compose";
import { GroupByOpts, Reducer } from "../api";
import { $$reduce, reducer } from "../reduce";
import { push } from "./push";

Expand Down
2 changes: 1 addition & 1 deletion packages/transducers/src/rfn/group-by-obj.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IObjectOf } from "@thi.ng/api";
import { identity } from "@thi.ng/compose";
import { GroupByOpts, Reducer } from "../api";
import { identity } from "../func/identity";
import { $$reduce, reducer } from "../reduce";
import { push } from "./push";

Expand Down
2 changes: 1 addition & 1 deletion packages/transducers/src/step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { push } from "./rfn/push";
* // [ 1, 2, 3 ]
*
* // no result
* f = step(filter(even))
* f = step(filter((x) => !(x & 1)))
* f(1); // undefined
* f(2); // 2
*
Expand Down
6 changes: 3 additions & 3 deletions packages/transducers/src/xform/delayed.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Transducer } from "../api";
import { delay } from "../func/delay";
import { delayed as _delayed } from "@thi.ng/compose";
import { map } from "./map";

/**
* Yields transducer which wraps incoming values in promises, which
* Yields transducer which wraps incoming values in promises, which each
* resolve after specified delay time (in ms).
*
* **Only to be used in async contexts and NOT with `transduce`
Expand All @@ -13,4 +13,4 @@ import { map } from "./map";
*/
export const delayed =
<T>(t: number): Transducer<T, Promise<T>> =>
map((x) => delay(x, t));
map((x) => _delayed(x, t));
2 changes: 1 addition & 1 deletion packages/transducers/src/xform/keep.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { identity } from "@thi.ng/compose";
import { Reducer, Transducer } from "../api";
import { compR } from "../func/compr";
import { identity } from "../func/identity";
import { $iter } from "../iterator";

export function keep<T>(pred?: (x: T) => any): Transducer<T, T>;
Expand Down
2 changes: 1 addition & 1 deletion packages/transducers/src/xform/moving-median.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { compare as cmp } from "@thi.ng/compare";
import { identity } from "@thi.ng/compose";
import { SortOpts, Transducer } from "../api";
import { comp } from "../func/comp";
import { identity } from "../func/identity";
import { $iter } from "../iterator";
import { map } from "./map";
import { partition } from "./partition";
Expand Down
2 changes: 1 addition & 1 deletion packages/transducers/src/xform/multiplex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { juxt } from "@thi.ng/compose";
import { Transducer } from "../api";
import { juxt } from "../func/juxt";
import { step } from "../step";
import { map } from "./map";

Expand Down
3 changes: 1 addition & 2 deletions packages/transducers/src/xform/partition-sort.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { compare as cmp } from "@thi.ng/compare";

import { identity } from "@thi.ng/compose";
import { SortOpts, Transducer } from "../api";
import { comp } from "../func/comp";
import { identity } from "../func/identity";
import { $iter, iterator } from "../iterator";
import { mapcat } from "./mapcat";
import { partition } from "./partition";
Expand Down
2 changes: 1 addition & 1 deletion packages/transducers/src/xform/partition-sync.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IObjectOf } from "@thi.ng/api";
import { isArray } from "@thi.ng/checks";
import { identity } from "@thi.ng/compose";
import { Reducer, Transducer } from "../api";
import { identity } from "../func/identity";
import { $iter, iterator } from "../iterator";

export interface PartitionSyncOpts<T> {
Expand Down
2 changes: 1 addition & 1 deletion packages/transducers/src/xform/stream-sort.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { binarySearch } from "@thi.ng/arrays";
import { compare as cmp } from "@thi.ng/compare";
import { identity } from "@thi.ng/compose";
import { Reducer, SortOpts, Transducer } from "../api";
import { identity } from "../func/identity";
import { $iter, iterator } from "../iterator";
import { isReduced } from "../reduced";

Expand Down
4 changes: 2 additions & 2 deletions packages/transducers/test/permutations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { swizzler } from "@thi.ng/arrays";
import { swizzle } from "@thi.ng/arrays";
import { permutations, permutationsN } from "../src/iter/permutations";
import { range } from "../src/iter/range";
import { iterator } from "../src/iterator";
Expand Down Expand Up @@ -41,7 +41,7 @@ describe("permutations", () => {
});
it("swizzle", () => {
assert.deepEqual(
[...iterator(map((x: string[]) => swizzler(x)({ x: 0, y: 1, z: 2 })), permutations("xyz", "xyz", "xyz"))],
[...iterator(map((x: string[]) => swizzle(x)({ x: 0, y: 1, z: 2 })), permutations("xyz", "xyz", "xyz"))],
[...permutationsN(3)]
);
});
Expand Down

0 comments on commit 05bf213

Please sign in to comment.