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
.
Find Product
s by any field.
Products
from list of Product
s.
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
add(products, product)
Specs
add(t(), ExKcal.Product.t()) :: {:ok, t()} | {:noop, :already_member}
Add Product
to Products
.
find(regex, products, fields \\ [:name, :description])
Specs
Find Product
s 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.
from_list(list)
Specs
from_list([ExKcal.Product.t()]) :: t()
Products
from list of Product
s.
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.
new()
Specs
new() :: t()
Get new instance of Products
struct. Equivalent of %Products{map: %{}}
.