View Source ExRoseTree.Zipper.Location (ExRoseTree v0.1.3)
A Location
in the path
from the root of the ExRoseTree.Zipper
to its
current context.
Link to this section 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 Location
s 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 ExRoseTree
s.
Link to this section 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.
term
is anExRoseTree
term
.prev
is a list ofExRoseTree
s. They are the siblings that occur prior theterm
. It is reversed such that the head of the list is the nearest previous sibling.next
is a list ofExRoseTree
s. They are the siblings that occur after theterm
.
Link to this section Guards
Link to this section Functions
Returns whether a list of values are all Location
s or not. Will return
true
if passed an empty list.
examples
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
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
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 ExRoseTree
s.
If the first argument is an ExRoseTree
, it will unwrap its term
element.
examples
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: []
}