Michał Muskała
unread,Dec 7, 2016, 11:40:27 AM12/7/16Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to elixir-l...@googlegroups.com
Hello everybody,
Today the hat/pin operator (^) only allows the variable as argument, but I think it would be completely valid for it to allow any expression. This feels like a natural extension, especially useful when dealing with map fields. The number of times I tried to write something like that, only to realise it will fail is "too damn high" :P
assert_received {:foo, ^map.foo}
The obvious fix is to transform this into
foo = map.foo
assert_received {:foo, ^foo}
But I wonder - couldn't this be done automatically by the compiler, to extract such things from the patterns in order to place them before the case expression? I could be missing something, especially around some semantic difference, but I though about this for some time, and couldn't see anything harmful.
Michał.