Structo (structo v0.1.3)
View SourceJavaScript-style object constructors.
This library allows you to construct maps and structs like this:
~m{a, b, c: d}
Instead of:
%{a: a, b: b, c: d}
And it works in matches too:
iex> ~m{a, b: 2} = %{a: 1, b: 2}
iex> a
1
Summary
Functions
This sigil acts as a shorthand for constructing maps with JavaScript-like syntax.
Functions
This sigil acts as a shorthand for constructing maps with JavaScript-like syntax.
Examples
iex> import Structo
iex> a = 1; b = 2; d = 3
iex> ~m{a, b, c: d}
%{a: 1, b: 2, c: 3}
Structs
This library can construct standard Elixir structs too:
iex> import Structo
iex> alias Hello.MyStruct
iex> a = 1
iex> ~m{:MyStruct, a, b: 2}
%Hello.MyStruct{a: 1, b: 2}
This syntax is preferred over the deprecated use Structo
behaviour,
which will be removed in the next release.