ExRoseTree. Zipper. Location
(ExRoseTree v0.1.4)
View Source
A Location in the path from the root of the ExRoseTree.Zipper to its
current context.
Summary
Types
A Location is made up of the term of an ExRoseTree with lists of prev and next siblings.
Functions
Returns whether a list of values are all Locations or not. Will return
true if passed an empty list.
Returns the index of the Location in relation to its siblings.
Applies the given function to the Location's term field.
Builds a new Location given a term() or an ExRoseTree as the first
argument, and optional :prev and :next keywords of lists of ExRoseTrees.
Guards
Types
@type t() :: %ExRoseTree.Zipper.Location{ next: [ExRoseTree.t()], prev: [ExRoseTree.t()], term: term() }
A Location is made up of the term of an ExRoseTree with lists of prev and next siblings.
termis anExRoseTreeterm.previs a list ofExRoseTrees. They are the siblings that occur prior theterm. It is reversed such that the head of the list is the nearest previous sibling.nextis a list ofExRoseTrees. They are the siblings that occur after theterm.
Functions
Returns whether a list of values are all Locations or not. Will return
true if passed an empty list.
Examples
iex> locs = for loc <- [5,4,3,2,1], do: ExRoseTree.Zipper.Location.new(loc)
...> ExRoseTree.Zipper.Location.all_locations?(locs)
true
@spec index_of_term(t()) :: non_neg_integer()
Returns the index of the Location in relation to its siblings.
Examples
iex> trees = for t <- [5,4,3,2,1], do: ExRoseTree.new(t)
...> loc = ExRoseTree.Zipper.Location.new(6, prev: trees, next: [])
...> ExRoseTree.Zipper.Location.index_of_term(loc)
5
Applies the given function to the Location's term field.
Examples
iex> loc = ExRoseTree.Zipper.Location.new(5, prev: [], next: [])
...> ExRoseTree.Zipper.Location.map_term(loc, &(&1*2))
%ExRoseTree.Zipper.Location{prev: [], term: 10, next: []}
@spec new( ExRoseTree.t() | term(), keyword() ) :: t() | nil
Builds a new Location given a term() or an ExRoseTree as the first
argument, and optional :prev and :next keywords of lists of ExRoseTrees.
If the first argument is an ExRoseTree, it will unwrap its term element.
Examples
iex> ExRoseTree.Zipper.Location.new(5, prev: [], next: [])
%ExRoseTree.Zipper.Location{prev: [], term: 5, next: []}
iex> tree = ExRoseTree.new(4)
...> ExRoseTree.Zipper.Location.new(5, prev: [tree], next: [])
%ExRoseTree.Zipper.Location{
prev: [
%ExRoseTree{term: 4, children: []}
],
term: 5,
next: []
}