Zipper

public struct Zipper

Navigate an immutable n-ary Tree structure.

Associated Types

Instance Properties

  • The Tree wrapped by the Zipper.

    Declaration

    Swift

    public let tree: Tree
  • The stack of Crumb values that hold a history of the remaining parts of the tree that are not currently in focus.

    Declaration

    Swift

    public let breadcrumbs: Breadcrumbs
  • up

    Move the Zipper up in the tree.

    Declaration

    Swift

    public var up: Zipper? { get }
  • top

    Zipper wrapping the root of the Tree.

    Declaration

    Swift

    public var top: Zipper { get }
  • Declaration

    Swift

    public var children: [Zipper] { get }

    Return Value

    Zipper values for each subtree contained by the wrapped Tree, if it is a branch.

  • Declaration

    Swift

    public var siblings: [Zipper] { get }

    Return Value

    Zipper values for each sibling subtree of the wrapped Tree.

Initializers

  • Create a Zipper with a Tree and a history of remaining parts of the tree that are not currently in focus.

    Declaration

    Swift

    public init(_ tree: Tree, _ breadcrumbs: Breadcrumbs = Breadcrumbs())

Instance Methods

  • Move focus to the sub-tree with the given index.

    Throws

    TreeError if index is out of bounds.

    Declaration

    Swift

    public func move(to index: Int) throws -> Zipper
  • Move focus to the sub-tree through the given path.

    Throws

    TreeError if the given path is no good.

    Declaration

    Swift

    public func move(through path: [Int]) throws -> Zipper
  • Transform the value of the wrapped Tree.

    Declaration

    Swift

    public func update(_ transform: Transform<Branch, Leaf>) -> Zipper
  • Transform the leaf value of the wrapped Tree with the given value.

    Declaration

    Swift

    public func updateLeaf(_ transform: (Leaf) -> Leaf) -> Zipper
  • Update the leaf value of the wrapped Tree with the given value.

    Declaration

    Swift

    public func updateLeaf(_ value: Leaf) -> Zipper
  • Transform the branch value of the wrapped Tree with the given value.

    Declaration

    Swift

    public func updateBranch(_ transform: (Branch) -> Branch) -> Zipper
  • Replace the branch value of the wrapped Tree with the given value.

    Declaration

    Swift

    public func updateBranch(_ value: Branch) -> Zipper
  • Replace the value of the wrapped Tree with the given value.

    Declaration

    Swift

    public func update(value: Either<Branch, Leaf>) -> Zipper