Skip to content

Instantly share code, notes, and snippets.

@rlipscombe
Created October 10, 2023 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlipscombe/868bbde6990e5ba4fbecb1d101b6e7ba to your computer and use it in GitHub Desktop.
Save rlipscombe/868bbde6990e5ba4fbecb1d101b6e7ba to your computer and use it in GitHub Desktop.
-module(kvl).
-export([from_list/1]).
from_list(KVs) ->
from_list(KVs, #{}).
from_list([K, V | KVs], Acc) ->
from_list(KVs, Acc#{K => V});
from_list([], Acc) ->
Acc.
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
from_list_test() ->
?assertEqual(#{k1 => v1, k2 => v2}, from_list([k1, v1, k2, v2])).
-endif.
@rlipscombe
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment