feat(lib/utils/trees): extract predicate type from filter in findInTree
This commit is contained in:
parent
f2d0602949
commit
17307bb90a
1 changed files with 5 additions and 3 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import type { ExtractPredicate } from './types'
|
||||
|
||||
export type SearchTree = Record<string, any>
|
||||
export type SearchFilter = (tree: SearchTree) => boolean
|
||||
|
||||
|
|
@ -18,11 +20,11 @@ export interface FindInTreeOptions {
|
|||
maxDepth?: number
|
||||
}
|
||||
|
||||
export function findInTree(
|
||||
export function findInTree<F extends SearchFilter>(
|
||||
tree: SearchTree,
|
||||
filter: SearchFilter,
|
||||
filter: F,
|
||||
opts?: FindInTreeOptions,
|
||||
): any | undefined {
|
||||
): ExtractPredicate<F> | undefined {
|
||||
type StackItem = [node: any, depth: number]
|
||||
const stack: StackItem[] = [[tree, 0]]
|
||||
const maxDepth = opts?.maxDepth ?? 100
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue