Elixir sigil for concise map and struct creation with automatic key-value inference from variable names.
ShorterMaps is an Elixir library that provides the `~M` and `~m` sigils as shorthand syntax for creating maps and structs. It reduces repetitive boilerplate code by inferring keys from variable names, similar to JavaScript's ES6 object shorthand, and supports pattern matching, updates, and nested usage.
Elixir developers who frequently work with maps and structs, especially those writing code with repetitive key-value pairs like `%{name: name, id: id}` or using pattern matching for destructuring.
Developers choose ShorterMaps because it makes Elixir code more concise and readable by eliminating verbose map syntax while maintaining full compatibility with Elixir's semantics, and it works anywhere in code due to compile-time macro expansion.
Elixir ~M sigil for map shorthand. ~M{id, name} ~> %{id: id, name: name}
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Eliminates repetitive map boilerplate by inferring keys from variable names, e.g., ~M{name} expands to %{name: name}, similar to JavaScript ES6 shorthand as noted in the README.
Works anywhere in Elixir code due to compile-time macro expansion, including function heads for pattern matching and nested usage, demonstrated in the examples.
Enables shorthand creation and updates for structs with syntax like ~M{%Person id, name}, integrating directly with Elixir's struct semantics without extra steps.
Allows mixing shorthand variables with explicit key-value pairs and expressions, such as ~M{name, id: id + 200}, for versatile map construction.
Requires importing ShorterMaps in every module, adding boilerplate setup and potential namespace pollution, which the README explicitly mandates.
Introduces custom sigils that deviate from vanilla Elixir, potentially confusing developers unfamiliar with the library and hindering code readability in mixed teams.
Relies on compile-time macro expansion, which can lead to cryptic error messages and subtle debugging challenges, a common trade-off in macro-based libraries.