I'd like to create a record from a list of attributes - not the actual proplist, but for example from #xmlElement
attributes. I've got a list of elements which I need to process and a list of possible attributes.
I could of course do something like:
create_record(Rec, [{attr1, Val}|As]) -> create_record(Rec#blah{attr1 = Val}, As);
create_record(Rec, [{attr2, Val}|As]) -> create_record(Rec#blah{attr2 = Val}, As);
...
But that's going to be a bit long and I already have the list of possible attributes (I could even use record_info(fields, blah)
. I see a lot of crazy ways to do it with accessing the actual record tuple with setelement, but maybe there's a simpler solution?