Skip to content

Commit

Permalink
feat(associative): update MultiTrie.suffixes()
Browse files Browse the repository at this point in the history
- add opt separator arg for arraylike keys
  • Loading branch information
postspectacular committed Jul 24, 2020
1 parent cc2d139 commit ec110ae
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/associative/src/multi-trie.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { IObjectOf, Pair, Fn0, Nullable } from "@thi.ng/api";
import type { Fn0, IObjectOf, Nullable, Pair } from "@thi.ng/api";
import { isArray } from "@thi.ng/checks";
import { map, vals } from "@thi.ng/transducers";

export interface MultiTrieOpts<V> {
Expand Down Expand Up @@ -57,10 +58,17 @@ export class MultiTrie<K extends ArrayLike<any>, V> {
}
}

*suffixes(prefix: K, withPrefix = false) {
*suffixes(prefix: K, withPrefix = false, sep = "") {
const node = this.find(prefix);
if (node) {
yield* node.keys("", withPrefix ? prefix.toString() : "");
yield* node.keys(
sep,
withPrefix
? isArray(prefix)
? prefix.join(sep)
: prefix.toString()
: ""
);
}
}

Expand Down

0 comments on commit ec110ae

Please sign in to comment.