Requiring Keys For Structs
defmodule Name do
@enforce_keys [:first, :last]
defstruct [:first, :middle, :last]
end> jack = %Name{first: "Jack", middle: "Francis", last: "Donaghy"}
%Name{first: "Jack", last: "Donaghy", middle: "Francis"}> liz = %Name{first: "Liz", last: "Lemon"}
%Name{first: "Liz", last: "Lemon", middle: nil}> tracy = %Name{first: "Tracy"}
** (ArgumentError) the following keys must also be given when building struct Name: [:last]
expanding struct: Name.__struct__/1
iex:6: (file)Last updated