anders

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

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.

Where Next?

Popular in Discussions Top

kostonstyle
Hi all How can I compare haskell with elixir, included tools, webservices, ect. Thanks
New
rms.mrcs
A couple of days ago I was discussing with a friend about different approaches to write microservices. He said that if he was going to w...
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
nburkley
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
New
jeramyRR
This is an interesting article to read. Elixir’s performance, like usual, is excellent. However, it seems like the high CPU usage is co...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
Jayshua
I recently came across the javascript library htmx. It reminded me a lot of liveview so I thought the community here might be interested....
New
matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New
shishini
I think this twitter post and youtube video didn’t get as much attention as I hoped I am still new to Elixir, so can’t really judge ...
New

Other popular topics Top

jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New

We're in Beta

About us Mission Statement