ExKcal.Products (ExKcal v0.0.8)

Main purpose of the module is to represent set of products and primitives required to manipulate it. It's analog of MapSet, but MapSet leaves us in uneasy situation, as its implementation details are private (opaque type) so there is no clean way of using it in guards (without (ab)using knowledge of hidden implementation details), and there are very few primitives accompanying it. ExKcal.Products offers something similar, doesn't hide implementation details, and builds upon them.

Link to this section Summary

Functions

Add Product to Products.

Products from list of Products.

Get Product by content of the name field. Exact match is required.

Get new instance of Products struct. Equivalent of %Products{map: %{}}.

Link to this section Types

Specs

t() :: %ExKcal.Products{map: %{required(ExKcal.Product.t()) => nil}}

Link to this section Functions

Link to this function

add(products, product)

Specs

add(t(), ExKcal.Product.t()) :: {:ok, t()} | {:noop, :already_member}

Add Product to Products.

Link to this function

find(regex, products, fields \\ [:name, :description])

Specs

find(Regex.t(), t(), list()) :: {:ok, list()} | {:not_found, nil}

Find Products by any field.

Notes

Match is done against space-separated, merged list of requested fields. This means that there is only one end of line, not multiple like in case of multiple, separate fields.

Link to this function

from_list(list)

Specs

from_list([ExKcal.Product.t()]) :: t()

Products from list of Products.

Link to this function

get(products, name)

Specs

get(t(), String.t()) :: {:ok, ExKcal.Product.t()} | {:not_found, nil}

Get Product by content of the name field. Exact match is required.

Specs

new() :: t()

Get new instance of Products struct. Equivalent of %Products{map: %{}}.