Domo.TaggedTuple (Domo v1.2.8) View Source

Functions that works on tagged tuples for domain modelling

Link to this section Summary

Functions

Defines a tagged tuple inline.

Returns a tagged tuple by joining the tag chain with the value.

Returns the value from the tagged tuple when the tag chain matches.

Link to this section Functions

Defines a tagged tuple inline.

The operator is right-associative. It adds a tag or a chain of tags to a value.

Can be used in Expressions and Pattern Matching. Doesn't work in @type definitions, please, use standard tuple syntax {...} there.

Examples

iex> use Domo.TaggedTuple
...> Tag --- 12
{Tag, 12}

iex> use Domo.TaggedTuple
...> A --- Tag --- Chain --- 12
{A, {Tag, {Chain, 12}}}
Link to this macro

tag(value, tag_chain)

View Source (macro)

Returns a tagged tuple by joining the tag chain with the value.

The macro supports up to 6 links in the tag chain.

Example

iex> use Domo.TaggedTuple
...> tag(2.5, SomeTag)
{SomeTag, 2.5}

iex> use Domo.TaggedTuple
...> tag(7, {A, {Tag, Chain}})
{A, {Tag, {Chain, 7}}}
Link to this macro

untag!(tagged_tuple, tag_chain)

View Source (macro)

Returns the value from the tagged tuple when the tag chain matches.

Raises ArgumentError exception if the passed tag chain is not one that is in the tagged tuple. Supports up to 6 links in the tag chain.

Examples

iex> use Domo.TaggedTuple
...> value = {A, {Tag, {Chain, 2}}}
...> untag!(value, {A, {Tag, Chain}})
2

iex> use Domo.TaggedTuple
...> value = {Other, {Stuff, 2}}
...> untag!(value, {A, {Tag, Chain}})
** (ArgumentError) Tag chain {A, {Tag, Chain}} doesn't match one in the tagged tuple {Other, {Stuff, 2}}.