Module

Yoga.Tree.Extended.Path

Package
purescript-yoga-tree-utils
Repository
shamansir/purescript-yoga-tree-utils

#Path Source

newtype Path

Path is an array of positions of nodes required to be visited to reach some node. |

Constructors

Instances

#root Source

root :: Path

Root path. |

#advance Source

advance :: Int -> Path -> Path

Go deeper one level at the point with given index. |

#up Source

up :: Path -> Path

Go up one level. |

#toArray Source

toArray :: Path -> Array Int

Convert path to an array. |

#fromArray Source

fromArray :: Array Int -> Path

Create path from array. |

#depth Source

depth :: Path -> Int

How deep is this path in the tree. |

#fill Source

fill :: forall a. Tree a -> Tree (Path /\ a)

Fill every value in this tree with its full path. |

#find Source

find :: forall a. Path -> Tree a -> Maybe (Tree a)

Find a deeper tree node by its given path. |

#with Source

with :: forall a. Path -> (Tree a -> Tree a) -> Tree a -> Tree a

Call a function with the tree node at the given path. |

#traverse Source

traverse :: forall a b. (Path -> a -> Tree a -> b) -> Tree a -> Tree b

Walk around the complete tree, calling a function at every node with its path, value and children. |

#fillDepths Source

fillDepths :: forall a. Tree a -> Tree (Int /\ a)

Pair every value in the tree with how deep it is in this tree. |

#startsWith Source

startsWith :: Path -> Path -> Boolean

If first path contains full second path. They could be equal, but the second path couldn't be longer than the first one. Every path contains root. |

#posAt Source

posAt :: Path -> Int -> Maybe Int

Value at given depth. |

#lastPos Source

lastPos :: Path -> Maybe Int

Value at the last position. |

#isNextFor Source

isNextFor :: Path -> Path -> Boolean

If first path contains full second path, and the first path is exactly one level deeper than the second.

#safeAdvance Source

safeAdvance :: forall a. Path -> Int -> Tree a -> Path

Navigate deeper by given index but only if the index is in the bounds of how many children are accessibly by this path. |

#Dir Source

data Dir

Constructors

Instances

#existsAt Source

existsAt :: forall a. Path -> Tree a -> Boolean

If the tree contains something at given path. |

#safeUp Source

safeUp :: forall a. Path -> Tree a -> Path

Safely go one level up to the root. |

#safeDown Source

safeDown :: forall a. Path -> Tree a -> Path

Safely go one level deeper, when possible. |

#safeRight Source

safeRight :: forall a. Path -> Tree a -> Path

Safely go to the next neigbouring child from the same parent. |

#safeLeft Source

safeLeft :: forall a. Path -> Tree a -> Path

Safely go to the previous neigbouring child from the same parent. |

#advanceDir Source

advanceDir :: forall a. Path -> Dir -> Tree a -> Path

Safely (by checking bounds from this tree) advance this path one step in the requested direction: