GitHub

collect

Helper

import { collect } from '@daffodil/core'

Recurses through a tree, collecting each element in that tree and returning it in an array. The value of getKey should be a field that contains a list of the same type of object. Accepts an optional depth argument which will limit the traversal. This should be used for trees with circular references.

function collect<T>(
  obj: T
  getChildren: (val: T) => T[]
  depth?: number
): T[]

Parameters

Parameterobj: T
Description
ParametergetChildren: (val: T) => T[]
Description
Parameterdepth: number
Description