Closed
Description
Instead, we should prefer pattern matching. With the type system, we already get the benefits of checking if fields exist or not, in a more reliable and extensible way.
Here is an example from LiveView:
for entry <- conf.entries do
%UploadEntry{entry | preflighted?: entry.preflighted? || entry.ref in refs}
end
However, the code above does not catch typos on entry.ref
. This code, however, would:
for %UploadEntry{} = entry <- conf.entries do
%{entry | preflighted?: entry.preflighted? || entry.ref in refs}
end
Since we attach type information to variables when they are defined.