-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Labels
Milestone
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.
KiKoS0, lin72h, glhrmv, Trevoke, meraj-hiive and 4 morenicklayb, Keedix, bminevsb, slashdotdash, towry and 2 moretowry and slashmili