Containers
Containers are functional like data structures that help provide greater runtime safety and polymorphism.
This package is dependency free. There are some dev only deps, but the package only relies on Elixir.
Protocols
-
Appendable
- A container that provides an interface ofappend
. Safe againstnil
values. Namely when passing a container with the valuenil
into either the first of second argument toappend
, the other value is not change and there is no runtime error. -
Mappable
- A container that provides an interface tomap
. Whenmap
is called on a container that has anil
value that container just passes through with out the mapping function being called, and this helps prevent runtime errors. -
Sequenceable
- A container that provides an interface ofnext
. This allows the chaining of computations. -
Unwrappable
- A container that provides an interface tosafe
andunsafe
unwrapping of inner value. Safe will need a default in case ofnil
value of container, helping prevent runtime errors. Unsafe will just return the value of the container regardless of anil
value potentially causing runtime errors -
Joinable
- A container that has a nested container of the same type, and is able to be join down into a single representation of the structure.
Since these are protocols, and highly decoupled, a developer can implement them as needed on their own structs.
Installation
The package can be installed by adding containers
to your list of dependencies in mix.exs
:
def deps do
[{:containers, "~> 0.7.1"}]
end
Note
Until version 1.0.0
assume minor changes (that is the number in the second spot) to reflect breaking changes.