Taxo (Taxo v0.1.0)

View Source

Taxo is an Elixir port of the Clojure hierarchies provided by derive and underive.

Summary

Functions

Returns the ancestors of a given child in the taxonomy taxo.

Establish a parent/child relationship in taxo between child and parent. Updates :parents, then transitively updates :ancestors and :descendants.

Returns the descendants of a given child in the taxonomy taxo.

Returns true if (= child parent), or child is directly or indirectly derived from parent.

Create a new taxonomy to store the :parents, :ancestors and :descendants of parent/child relationships, updated via derive and underive. Updates :parents, then transitively updates :ancestors and :descendants.

Returns the parents of a given child in the taxonomy taxo.

Removes a parent/child relationship in taxo between child and parent. Updates :parents, then transitively updates :ancestors and :descendants.

Functions

ancestors(taxo, child)

Returns the ancestors of a given child in the taxonomy taxo.

## Examples

  iex> Taxo.new |> Taxo.derive(:monkey, :mammal) |> Taxo.ancestors(:monkey)
  MapSet.new([:mammal])

derive(taxo, child, parent)

Establish a parent/child relationship in taxo between child and parent. Updates :parents, then transitively updates :ancestors and :descendants.

Examples

iex> Taxo.new |> Taxo.derive(:monkey, :mammal)
%Taxo{
  ancestors: %{monkey: MapSet.new([:mammal])},
  parents: %{monkey: MapSet.new([:mammal])},
  descendants: %{mammal: MapSet.new([:monkey])}
}

descendants(taxo, child)

Returns the descendants of a given child in the taxonomy taxo.

## Examples

  iex> Taxo.new |> Taxo.derive(:monkey, :mammal) |> Taxo.descendants(:mammal)
  MapSet.new([:monkey])

is_a?(taxo, child, parent)

Returns true if (= child parent), or child is directly or indirectly derived from parent.

Examples

iex> Taxo.new |> Taxo.derive(:monkey, :mammal) |> Taxo.derive(:mammal, :vertebrate) |> Taxo.is_a?(:monkey, :vertebrate)
true

iex> Taxo.new |> Taxo.derive(:monkey, :mammal) |> Taxo.derive(:mammal, :vertebrate) |> Taxo.is_a?(:vertebrate, :monkey)
false

new()

Create a new taxonomy to store the :parents, :ancestors and :descendants of parent/child relationships, updated via derive and underive. Updates :parents, then transitively updates :ancestors and :descendants.

Examples

iex> Taxo.new
%Taxo{ancestors: %{}, parents: %{}, descendants: %{}}

parents(taxo, child)

Returns the parents of a given child in the taxonomy taxo.

## Examples

  iex> Taxo.new |> Taxo.derive(:monkey, :mammal) |> Taxo.parents(:monkey)
  MapSet.new([:mammal])

underive(taxo, child, parent)

Removes a parent/child relationship in taxo between child and parent. Updates :parents, then transitively updates :ancestors and :descendants.

Examples

iex> Taxo.derive(%{}, :monkey, :mammal) |> Taxo.underive(:monkey, :mammal)
%Taxo{ancestors: %{}, parents: %{}, descendants: %{}}