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

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 20046 166
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
acrolink
How does the two languages compare when it comes to server side application development? Any experiences or ideas? Thank you.
New
tmbb
This is a post to discuss the new Phoenix LiveView functionality. From Chris’s talk, it appears that they generate all HTML on the serve...
342 18584 126
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement