|
Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg This software is released under an open source BSD licence. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfj.data.TreeZipper<A>
public class TreeZipper<A>
Provides a zipper structure for rose trees, which is a Tree supplied with a location within that tree. Provides navigation, insertion, deletion, and memorization of visited locations within a tree.
Method Summary | ||
---|---|---|
|
cobind(F<TreeZipper<A>,B> f)
Maps the given function over the tree of all positions for this zipper (comonad pattern). |
|
Option<TreeZipper<A>> |
delete()
Removes the current node from the tree. |
|
static
|
eq(Equal<A> e)
An Equal instance for tree zippers. |
|
static
|
findChild()
A first-class version of the findChild function. |
|
Option<TreeZipper<A>> |
findChild(F<Tree<A>,Boolean> p)
Navigates to the first child of the current location, that satisfies the given predicate. |
|
Option<TreeZipper<A>> |
firstChild()
Navigtes to the first child of the current location. |
|
Tree<A> |
focus()
Returns the tree at the currently focused node. |
|
static
|
fromForest(Stream<Tree<A>> ts)
Creates a new tree zipper focused on the first element of the given forest. |
|
static
|
fromTree()
First-class conversion of a Tree to the corresponding tree zipper. |
|
static
|
fromTree(Tree<A> t)
Creates a new tree zipper focused on the root of the given tree. |
|
Option<TreeZipper<A>> |
getChild(int n)
Navigates to the given child of the current location, starting at index 0. |
|
A |
getLabel()
Returns the label at the current node. |
|
boolean |
hasChildren()
Indicates whether the current node has any child nodes. |
|
Option<TreeZipper<A>> |
insertDownAt(int n,
Tree<A> t)
Inserts a tree at the specified location in the current node's stream of children. |
|
TreeZipper<A> |
insertDownFirst(Tree<A> t)
Inserts a tree as the first child of the current node. |
|
TreeZipper<A> |
insertDownLast(Tree<A> t)
Inserts a tree as the last child of the current node. |
|
TreeZipper<A> |
insertLeft(Tree<A> t)
Inserts a tree to the left of the current position. |
|
TreeZipper<A> |
insertRight(Tree<A> t)
Inserts a tree to the right of the current position. |
|
boolean |
isChild()
Indicates whether the current node is a child node of another node. |
|
boolean |
isFirst()
Indicates whether the current node is the leftmost tree in the current forest. |
|
boolean |
isLast()
Indicates whether the current node is the rightmost tree in the current forest. |
|
boolean |
isLeaf()
Indicates whether the current node is at the bottom of the tree. |
|
boolean |
isRoot()
Indicates whether the current node is at the top of the tree. |
|
Iterator<TreeZipper<A>> |
iterator()
Returns an iterator of all the positions of this TreeZipper. |
|
Option<TreeZipper<A>> |
lastChild()
Navigtes to the last child of the current location. |
|
static
|
left_()
A first-class version of the left() function. |
|
Option<TreeZipper<A>> |
left()
Navigates to the left sibling of the current location. |
|
Stream<Tree<A>> |
lefts()
Returns the left siblings of the currently focused node. |
|
|
map(F<A,B> f)
Maps the given function across this zipper (covariant functor pattern). |
|
TreeZipper<A> |
modifyLabel(F<A,A> f)
Modifies the label at the current node with the given function. |
|
TreeZipper<A> |
modifyTree(F<Tree<A>,Tree<A>> f)
Modifies the current node with the given function. |
|
static
|
p_()
A first-class function that returns the product-4 representation of a given zipper. |
|
P4<Tree<A>,Stream<Tree<A>>,Stream<Tree<A>>,Stream<P3<Stream<Tree<A>>,A,Stream<Tree<A>>>>> |
p()
Returns the product-4 representation of this zipper. |
|
Option<TreeZipper<A>> |
parent()
Navigates to the parent of the current location. |
|
TreeZipper<TreeZipper<A>> |
positions()
Returns a zipper over the tree of all possible permutations of this tree zipper (comonad pattern). |
|
static
|
right_()
A first-class version of the right() function. |
|
Option<TreeZipper<A>> |
right()
Navigates to the right sibling of the current location. |
|
Stream<Tree<A>> |
rights()
Returns the right siblings of the currently focused node. |
|
static
|
root_()
A first-class version of the root function. |
|
TreeZipper<A> |
root()
Navigates to the top-most parent of the current location. |
|
TreeZipper<A> |
setLabel(A v)
Replaces the label of the current node with the given value. |
|
TreeZipper<A> |
setTree(Tree<A> t)
Replaces the current node with the given tree. |
|
static
|
show(Show<A> s)
A Show instance for tree zippers. |
|
Stream<Tree<A>> |
toForest()
Returns the forest containing this location. |
|
Tree<A> |
toTree()
Returns the tree containing this location. |
|
static
|
treeZipper()
First-class constructor for tree zippers. |
|
static
|
treeZipper(Tree<A> tree,
Stream<Tree<A>> lefts,
Stream<Tree<A>> rights,
Stream<P3<Stream<Tree<A>>,A,Stream<Tree<A>>>> parents)
Creates a new tree zipper given a currently selected tree, a forest on the left, a forest on the right, and a stream of parent contexts. |
|
|
zipWith(TreeZipper<B> bs,
F<A,F<B,C>> f)
Zips this TreeZipper with another, applying the given function lock-step over both zippers in all directions. |
|
|
zipWith(TreeZipper<B> bs,
F2<A,B,C> f)
Zips this TreeZipper with another, applying the given function lock-step over both zippers in all directions. |
|
TreeZipper<P2<A,Boolean>> |
zipWithFocus()
Zips the nodes in this zipper with a boolean that indicates whether that node has focus. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public Iterator<TreeZipper<A>> iterator()
iterator
in interface Iterable<TreeZipper<A>>
public static <A> TreeZipper<A> treeZipper(Tree<A> tree, Stream<Tree<A>> lefts, Stream<Tree<A>> rights, Stream<P3<Stream<Tree<A>>,A,Stream<Tree<A>>>> parents)
tree
- The currently selected tree.lefts
- The selected tree's left siblings, closest first.rights
- The selected tree's right siblings, closest first.parents
- The parent of the selected tree, and the parent's siblings.
public static <A> F<Tree<A>,F<Stream<Tree<A>>,F<Stream<Tree<A>>,F<Stream<P3<Stream<Tree<A>>,A,Stream<Tree<A>>>>,TreeZipper<A>>>>> treeZipper()
public P4<Tree<A>,Stream<Tree<A>>,Stream<Tree<A>>,Stream<P3<Stream<Tree<A>>,A,Stream<Tree<A>>>>> p()
public static <A> F<TreeZipper<A>,P4<Tree<A>,Stream<Tree<A>>,Stream<Tree<A>>,Stream<P3<Stream<Tree<A>>,A,Stream<Tree<A>>>>>> p_()
public static <A> Equal<TreeZipper<A>> eq(Equal<A> e)
e
- An Equal instance for tree elements.
public static <A> Show<TreeZipper<A>> show(Show<A> s)
s
- A Show instance for tree elements.
public Option<TreeZipper<A>> parent()
public TreeZipper<A> root()
public static <A> F<TreeZipper<A>,TreeZipper<A>> root_()
public Option<TreeZipper<A>> left()
public Option<TreeZipper<A>> right()
public Option<TreeZipper<A>> firstChild()
public Option<TreeZipper<A>> lastChild()
public Option<TreeZipper<A>> getChild(int n)
n
- The index of the child to which to navigate.
public Option<TreeZipper<A>> findChild(F<Tree<A>,Boolean> p)
p
- A predicate to be satisfied by the child node.
public static <A> TreeZipper<A> fromTree(Tree<A> t)
t
- A tree over which to create a new zipper.
public static <A> Option<TreeZipper<A>> fromForest(Stream<Tree<A>> ts)
ts
- A forest over which to create a new zipper.
public Tree<A> toTree()
public Stream<Tree<A>> toForest()
public Tree<A> focus()
public Stream<Tree<A>> lefts()
public Stream<Tree<A>> rights()
public boolean isRoot()
public boolean isFirst()
public boolean isLast()
public boolean isLeaf()
public boolean isChild()
public boolean hasChildren()
public TreeZipper<A> setTree(Tree<A> t)
t
- A tree with which to replace the current node.
public TreeZipper<A> modifyTree(F<Tree<A>,Tree<A>> f)
f
- A function with which to modify the current tree.
public TreeZipper<A> modifyLabel(F<A,A> f)
f
- A function with which to transform the current node's label.
public TreeZipper<A> setLabel(A v)
v
- The new value for the node's label.
public A getLabel()
public TreeZipper<A> insertLeft(Tree<A> t)
t
- A tree to insert to the left of the current position.
public TreeZipper<A> insertRight(Tree<A> t)
t
- A tree to insert to the right of the current position.
public TreeZipper<A> insertDownFirst(Tree<A> t)
t
- A tree to insert.
public TreeZipper<A> insertDownLast(Tree<A> t)
t
- A tree to insert.
public Option<TreeZipper<A>> insertDownAt(int n, Tree<A> t)
n
- The index at which to insert the given tree, starting at 0.t
- A tree to insert.
n
children.public Option<TreeZipper<A>> delete()
public TreeZipper<P2<A,Boolean>> zipWithFocus()
public <B> TreeZipper<B> map(F<A,B> f)
f
- A function to map across this zipper.
public static <A> F<Tree<A>,TreeZipper<A>> fromTree()
public static <A> F<TreeZipper<A>,Option<TreeZipper<A>>> left_()
public static <A> F<TreeZipper<A>,Option<TreeZipper<A>>> right_()
public TreeZipper<TreeZipper<A>> positions()
public <B> TreeZipper<B> cobind(F<TreeZipper<A>,B> f)
f
- A function to map over the tree of all positions for this zipper.
public static <A> F2<F<Tree<A>,Boolean>,TreeZipper<A>,Option<TreeZipper<A>>> findChild()
public <B,C> TreeZipper<C> zipWith(TreeZipper<B> bs, F2<A,B,C> f)
bs
- A TreeZipper to zip this one with.f
- A function with which to zip together the two TreeZippers.
public <B,C> TreeZipper<C> zipWith(TreeZipper<B> bs, F<A,F<B,C>> f)
bs
- A TreeZipper to zip this one with.f
- A function with which to zip together the two TreeZippers.
|
Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg This software is released under an open source BSD licence. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |