effect-tree - v1.0.36
    Preparing search index...

    Function unfoldLevelTree

    • Unfold a perfectly balanced tree from the given settings.

      The numeric argument for the TreeUnfold<number,number> returned, is the lower limit for the depth and you would usually want the default 1.

      When the limit is 1 and the depth is 7, then 7 levels will be build. If the depth is 7 but the limit is 3, only 4 levels will be built, and the root node value will be 4.

      In a level tree, the value of every node is its depth. This, for example, is a level tree:

      ┬1
      ├─2
      ├─2
      ├┬2
      │├─3
      │└─3
      └─2
      

      Parameters

      Returns (lowerLimit?: number) => Tree<number>

      import {unfoldLevelTree, Draw} from 'effect-tree'

      const tree = unfoldLevelTree({depth: 4, degree: depth => 3 - depth})()

      expect(Draw.drawTree.number(tree)).toEqual([
      '┬1 ',
      '├┬2 ',
      '│└┬3 ',
      '│ └─4',
      '└┬2 ',
      ' └┬3 ',
      ' └─4',
      ])