Reputation: 6366
See my attempt at a record definition below. The Erlang compiler doesn't consider the key
field definition as valid syntax.
Is there a way to accomplish something similar, without making key a record or just a undefined tuple structure like key :: tuple()
?
-record(spot, {
key :: {id :: integer(), version:: integer(), live :: boolean()},
name :: binary(),
short_description :: binary(),
address1 :: binary(),
address2 :: binary(),
address3 :: binary(),
postalcode :: binary(),
city :: binary(),
phone :: binary(),
website_url :: binary(),
menu_url :: binary(),
last_modified_at :: erlang:timestamp()}).
Upvotes: 3
Views: 97
Reputation: 26121
{id :: integer(), version:: integer(), live :: boolean()}
is not valid type specification. You can use record definition or you have to specify only type information which is {integer(), integer(), boolean()}
.
So using record would look like.
-record(spot_key, {
id :: integer(),
version:: integer(),
live :: boolean()
}).
-record(spot, {
key :: #spot_key{},
name :: binary(),
short_description :: binary(),
address1 :: binary(),
address2 :: binary(),
address3 :: binary(),
postalcode :: binary(),
city :: binary(),
phone :: binary(),
website_url :: binary(),
menu_url :: binary(),
last_modified_at :: erlang:timestamp()
}).
Upvotes: 5
Reputation: 5998
If you dont want to create record for key, you cannot use field names in the key tuple. If you remove that field names , I believe compiler will be able to eat it.
I mean try instead of
-record(spot, {
key :: {id :: integer(), version:: integer(), live :: boolean()},
name :: binary(),
write
-record(spot, {
key :: {integer(), integer(), boolean()},
name :: binary(),
Upvotes: 3