anders
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})
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
The obligatory hello world thread!
Who are you and where are you from? :stuck_out_tongue:
New
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project.
My initial shotgu...
New
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog
It says that Fly is going all-in on sprites, which is a worry ...
New
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using.
We’re particularly inte...
New
Is there a word for the ~> symbol used in Version strings?
Do you also just call it a Squiggle Arrow™ ?!
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
Chat & Discussions>Discussions
Latest on Elixir Forum
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
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 6- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
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
:somethingmaps to an atom andsomethingdoes a string key match instead of the trailing modifier.sotojuan
I was surprised to learn Elixir doesn’t support this as it seems similar to pattern matching. @josevalim why is this?
anders
Thaks for pointing me to the library @OvermindDL1!
Also found a link to a discussion on the elixir mailing list on the short_maps librarys github page.
OvermindDL1
There was actually a huge conversation about this with jose a while back at: Redirecting to Google Groups
EDIT: @anders beat me to the link. ^.^
OvermindDL1
On an aside, I’d love this syntax or:
It would be able to handle all the basic types for anything from phoenix param matching to erlang strings to atoms to going back to normal pattern matching. Even if this were as a sigil maybe like
m%{:a, "b", :c => d, 'e', f: m%{:g}}or something. Could have a base case of an undecorated variable fall back to being just an atom (the default case), and support adding ^ to any of them to match an equal named variable.anders
Perhaps it’s because I’m new to elixir (and not used to seeing sigils), but the “undecorated” style is much more appealing to me. This feature is all about reducing character noise and repetition and, to me, the sigils introduce another kind of noise that makes the code less fluent to read.