Hey guys (and gals),
Letting you know I finally release this Extructure library. Here’s some info copied from its docs:
By default the library is using loose (flexible) matching, allowing for implicit structural conversions (maps, lists and tuples, from one to another). Tuple and list key pair element order are also taken loosely by default.
Supports destructure-like implicit keys (with the same name as the variable) as well as optional values, flexible keyword and key pair tuple size and order of elements, implicit transformation between a map, list and a key pair tuple.
Also supports toggling between the loose mode and the standard Elixir pattern matching (“rigid”) mode where none of the flexibilities except for the optional variables are allowed.
Fully enforces pattern matching between the left and right side once taken into account the optional values and structural transformation.
For example, instead of:
%{
first_name: fist_name,
last_name: last_name,
} = socket.assigns
age = socket.assigns[ :age]
just write:
%{ first_name, last_name, _age} <~ socket.assigns
or implicitly transform the map into a list:
[ first_name, last_name, _age] <~ socket.assigns
or use a different order:
[ last_name, _age, first_name] <~ socket.assigns
or set a default value:
[ last_name, age( 25), first_name] <~ socket.assigns
Enjoy!