How can I enforce all keys in a structure without having to duplicate all keys? To clarify, I would like to do this:
defmodule Ticket do @enforce_keys [:origin, :destination, :price] defstruct [:origin, :destination, :price] end
I can use an additional variable:
defmodule Ticket do struct_keys = [:origin, :destination, :price] @enforce_keys struct_keys defstruct struct_keys end
It works correctly, but it looks noisy. Is there a better approach?
source share