Pathex.Combination (Pathex v1.3.0) View Source

Module for combination structures

Link to this section Summary

Types

Plain representation of one path for generating one case(do:) or one matchable case

t()

Representation of one path combination

Functions

Simply transforms passed path into combination

Counts total size of clauses created from this composition

Transforms combination into list of paths this combination defines

Link to this section Types

Specs

path() :: [{struct_type(), any()}]

Plain representation of one path for generating one case(do:) or one matchable case

Specs

t() :: [[{struct_type(), Macro.t()}]]

Representation of one path combination

For example:

[
  [map: :x, keyword: :x]
  [map: :y]
]

Will expand to

case do
  %{x: inner} ->
    case inner do
      %{y: value} -> {:ok, value}
      _ -> :error
    end

  [_ | _] = keyword->
    case Keyword.fetch(keyword, :x) do
      {:ok, inner} ->
        case inner do
          %{y: value} -> {:ok, value}
          _ -> :error
        end
      _ ->
        :error
    end

  _ ->
    :error
end

Link to this section Functions

Specs

from_path(path()) :: t()

Simply transforms passed path into combination

Specs

size(t()) :: non_neg_integer()

Counts total size of clauses created from this composition

Specs

to_paths(t()) :: [path()]

Transforms combination into list of paths this combination defines