hst337

hst337

Bug in Elixir? Map update in guards

Why map update syntax does not work in guards?

1> case [1, 2, 3] of
1>   X when #{x => 1}#{x => 2} =:= #{x => 2} -> X
1> end.
[1,2,3]

and

iex> case [1, 2, 3] do
...>   x when %{%{x: 1} | x: 2} == %{x: 2} -> x
...> end

Should I submit it as a bug, or is it intended?

Most Liked

hst337

hst337

I thought about something like

defguard is_same_struct?(left, right) when %{left | meta: nil} == %{right | meta: nil}

Or

defguard equal_request?(left, right) when %{left | timestamp: nil} == %{right | timestamp: nil}
josevalim

josevalim

Creator of Elixir

IIRC Erlang supports only updates of literal values and I am not sure there is a need for it in Elixir because you could merge them at compile time if you need similar behavior.

trisolaran

trisolaran

What would be the use case for this? Isn’t the above guard checking whether 2 == 2? :thinking:

Last Post!

hst337

hst337

This works only if you know all the keys by name.

Where Next?

Popular in Discussions Top

ricklove
I was just introduced to Elixir and Phoenix. I was told about the 2 million websocket test that was done 2 years ago. From my research, t...
New
pillaiindu
In django there is a cache framework backed by memcached. Rails also puts a lot of emphasis on caching, and even the idea of russian-doll...
New
jer
I’ve been using umbrellas for a while, and generally started off (on greenfield projects at least) by isolating subapps based on clearly ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
AstonJ
If so I (and hopefully others!) might have some tips for you :slight_smile: But first, please say which area you’re finding most challen...
New
lucaong
Hello Elixir and Nerves community, I have been working for a while on an open-source embedded key-value database for Elixir, that I call...
230 14350 124
New
Fl4m3Ph03n1x
Background This question comes mainly from my ignorance. Today is Black Friday, one of my favorite days of the year to buy books. One boo...
New

Other popular topics Top

jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
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
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement