Skip to content

Instantly share code, notes, and snippets.

@archaelus
Created October 30, 2008 11:14
Show Gist options
  • Save archaelus/20968 to your computer and use it in GitHub Desktop.
Save archaelus/20968 to your computer and use it in GitHub Desktop.
info(Field, Rec) ->
Fields = fields(Rec),
FieldIdx = lists:zip(Fields, lists:seq(2,length(Fields)+1)),
element(proplists:get_value(Field,FieldIdx), Rec).
fields(#your_record{}) -> fields(your_record);
fields(your_record) -> record_info(fields, your_record).
to_proplist(R) ->
Keys = fields(R),
Values = tl(tuple_to_list(R)),
lists:zip(Keys,Values).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment