Tree

public final class Tree<A> : TreeOf<A>

Tree represents a non-empty tree that allows node to have an arbitrary number of children.

The Foldable instance walks through the tree in depth-first order.

  • Undocumented

    Declaration

    Swift

    public let root: A
  • Undocumented

    Declaration

    Swift

    public let subForest: [Tree<A>]
  • Safe downcast.

    Declaration

    Swift

    public static func fix(_ fa: TreeOf<A>) -> Tree<A>

    Parameters

    fa

    Value in higher-kind form.

    Return Value

    Value cast to Tree.

  • Initializes a tree.

    Declaration

    Swift

    public init(root: A, subForest: [Tree<A>])

    Parameters

    head

    First element for the array.

    tail

    An array with the rest of elements.

  • Adds a tree as a subtree of self.

    The root of tree will be place directly under the root of self.

    Declaration

    Swift

    public func appendSubTree(_ tree: Tree<A>) -> Tree<A>

    Parameters

    tree

    The tree to add under self.root.

    Return Value

    A tree with the same elements as self with tree added as subtree.

  • Adds a collection of trees as subtrees of self.

    The root of each subtree will be place directly under the root of self.

    Declaration

    Swift

    public func appendSubForest(_ subForest: [Tree<A>]) -> Tree<A>

    Parameters

    subForest

    A collection of trees to add under self.root

    Return Value

    A tree with the same elements as self with the trees of subForest added as subtrees.