anders
ES6-ish "property value shorthands" for maps?
Is there any discussion about adding something similar to ES6 “property value shorthands” to maps? I’m just getting started with elixir so I’m not sure where to look for this type of language discussion.
What do you think about the idea? Would it be possible?
In Java Script (ES6) one can create an object like this:
let x = 50;
let y = 100;
let coordinates = { x, y };
which is shorthand for:
var coordinates = { x: x, y: y }
It would be great to have some thing similar in elixir:
iex> fu = "bar"
"bar"
iex> %{fu} # Shorthand for %{fu: fu}
%{fu: "bar"}
and it could be used to bind variables in matches:
fn(%{x, y}) # Shorthand for fn(%{x: x, y: y})
Most Liked
OvermindDL1
Library is already made that does all that (in both atom and string key variants): short_maps | Hex ^.^
EDIT: Sadly it is an all or nothing right now, no mixing short and long form, which really sucks in some cases, but it is a feature that ‘could’ be added to it if someone were to PR it perhaps? Would also be cool to make the atom/string choosing direct so :something maps to an atom and something does a string key match instead of the trailing modifier.
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









