Skip to content

Commit

Permalink
feat(transducers): add sortedKeys() iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Dec 26, 2019
1 parent 1bc561b commit fa9343c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/transducers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export * from "./iter/range3d";
export * from "./iter/repeat";
export * from "./iter/repeatedly";
export * from "./iter/reverse";
export * from "./iter/sorted-keys";
export * from "./iter/symmetric";
export * from "./iter/tween";
export * from "./iter/vals";
Expand Down
14 changes: 14 additions & 0 deletions packages/transducers/src/iter/sorted-keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Comparator } from "@thi.ng/api";
import { compare } from "@thi.ng/compare";

/**
* Syntax sugar for `Object.keys(x).sort()` with support for custom
* comparator (default: {@link @thi.ng/compare#compare}) and yielding
* iterator of sorted keys.
*
* @param x -
* @param cmp -
*/
export function* sortedKeys(x: any, cmp: Comparator<string> = compare) {
yield* Object.keys(x).sort(cmp);
}

0 comments on commit fa9343c

Please sign in to comment.