title: Convert proplist to paired tuple
body: <p>This is the reverse of <a href="https://stackoverflow.com/questions/16816028/convert-tuples-to-proplists">"Convert tuples to proplists"</a>.</p>
  
  <p>I've got an Erlang proplist, potentially containing duplicate keys:</p>
  
  <pre><code>P = [{foo, "bar"},             % key = string (char list)
        baz, {quux, true},       % both true; one expanded
        {dog, "Rex"},            % this overrides the duplicate below
        {sum, 42},               % key = integer
        {dog, "Fido"},           % overriden above
        {colour, blue},          % key = atom
        {always, false}].        % opposite of baz or quux
  </code></pre>
  
  <p>I'd like to turn it into a paired tuple (suitable for <a href="https://github.com/mongodb/bson-erlang" rel="nofollow noreferrer">bson-erlang</a>) as follows:</p>
  
  <pre><code>{foo, "bar",
   baz, true,     % atom =&gt; {atom, true} =&gt; ..., atom, true, ...
   quux, true,
   dog, "Rex",    % the first one.
   sum, 42,
   colour, blue,
   always, false}
  </code></pre>
  
  <p>So, <code>[{k1, v1}, {k2, v2}, ...]</code> is now <code>{k1, v1, k2, v2, ...}</code>.</p>
  
  <p>The proplist is expanded; duplicate keys use the correct value (the first, as would be returned by <code>proplists:get_value/2</code>). In this case, the order of keys in the resulting tuple doesn't particularly matter.</p>
  
  <p>How do I do this in Erlang?</p>